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 开发者_JAVA百科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?
Use
<a href="page2.html?x=123"
onclick="location.replace(this.href); return false">Next</a>
to go forward while replacing the link in the history array
精彩评论