我有几个与浏览器后退按钮相关的问题:
我们要求当用户在应用程序中的某个位置单击应用程序中的后退按钮时,他将返回到错误页面。
实施必须通过Javasctipt。我尝试使用历史对象,但截至目前我被困住了。请帮帮我。
答案 0 :(得分:2)
1)如何识别上一页到达当前页面的URL
window.document.referrer
从页面打开的位置返回网址。
对于其他两个问题,以下是MDN的示例:
Example
Suppose http://mozilla.org/foo.html executes the following JavaScript:
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
This will cause the URL bar to display http://mozilla.org/bar.html, but won't cause the browser to load bar.html or even check that bar.html exists.
Suppose now that the user now navigates to http://google.com, then clicks back. At this point, the URL bar will display http://mozilla.org/bar.html, and the page will get a popstate event whose state object contains a copy of stateObj. The page itself will look like foo.html, although the page might modify its contents during the popstate event.
If we click back again, the URL will change to http://mozilla.org/foo.html, and the document will get another popstate event, this time with a null state object. Here too, going back doesn't change the document's contents from what they were in the previous step, although the document might update its contents manually upon receiving the popstate event.
答案 1 :(得分:0)
您可以使用document.referrer查看它们的来源。 也是一个很好的历史参考:https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history