Move backward through history skipping the same page with different query string

ε祈祈猫儿з 提交于 2019-12-12 07:27:39

问题


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:


Use

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

to go forward



来源:https://stackoverflow.com/questions/6220211/move-backward-through-history-skipping-the-same-page-with-different-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!