Move backward through history skipping the same pa

2019-02-25 02:58发布

When I refresh a page or redirect to the same one using the same url, I can click in a button with "window.history.back();" code and go back to the previous page.

However, If the query string was changed, I just back to the same page when I try to move back.

Example 1:

page1.html -> page2.html -> page2.html -> [click back button] -> page1.html

Example 2:

page1.html -> page2.html -> page2.html?x=123 -> [click back button] -> page2.html

What I want:

page1.html -> page2.html -> page2.html?x=123 -> [click back button] -> page1.html

So, the question is, Can I check if the page is the same using JavaScript to ignore query string changes and move back to the real previous page?

1条回答
何必那么认真
2楼-- · 2019-02-25 03:22

Use

<a href="page2.html?x=123" 
onclick="location.replace(this.href); return false">Next</a>

to go forward

查看更多
登录 后发表回答