{"id":470,"date":"2023-02-25T13:41:59","date_gmt":"2023-02-25T05:41:59","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=470"},"modified":"2023-04-29T20:55:33","modified_gmt":"2023-04-29T12:55:33","slug":"js-jump-block-back-to-previous-page-no-history","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/js-jump-block-back-to-previous-page-no-history\/","title":{"rendered":"JS\u8df3\u8f6c\u963b\u6b62\u540e\u9000\u81f3\u4e0a\u4e00\u9875\u9762\uff0c\u6ca1\u6709\u5386\u53f2\u8bb0\u5f55"},"content":{"rendered":"<h2>window.location.replace<\/h2>\n<pre><code class=\"language-javascript\">window.location.replace(&#039;\u8981\u8f6c\u5411\u7684\u9875\u9762&#039;)  \/\/\u4e0d\u4f1a\u6709\u5386\u53f2\u8bb0\u5f55<\/code><\/pre>\n<p><!-- more --><\/p>\n<pre><code class=\"language-javascript\">let backLen = history.length\nhistory.forward()\nhistory.go(-backLen) \/\/ Return at the beginning\nwindow.location.replace(&#039;\/#\/home&#039;)<\/code><\/pre>\n<h2>window.location.hash<\/h2>\n<p>JS\u901a\u8fc7\u6539\u53d8location.hash\u65f6\u6e05\u9664history<\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6765\u7ed9hash\u8d4b\u503c<\/p>\n<pre><code class=\"language-javascript\">window.location.hash = &#039;hash\u7684\u503c&#039;<\/code><\/pre>\n<p>\u4f1a\u5728window.history\u65b0\u589e\u4e00\u6761\u5386\u53f2\u8bb0\u5f55\uff0c\u5982\u679c\u60f3\u6e05\u9664\u6389\u8fd9\u6761\u8bb0\u5f55\uff08\u4e0d\u6e05\u9664\u7684\u8bdd\u70b9\u51fb\u8fd4\u56de\u4f1a\u56de\u5230\u4e0a\u4e00\u4e2ahash\u503c\u7684\u9875\u9762\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528<\/p>\n<pre><code class=\"language-javascript\">window.location.replace(window.location.href.toString().replace(window.location.hash, &#039;&#039;) + &quot;#&quot; + &quot;hash\u7684\u503c&quot;)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>window.location.replace window.location.replace(&#039;\u8981 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[84],"class_list":["post-470","post","type-post","status-publish","format-standard","hentry","category-frontend-basic","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=470"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/470\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}