2011-12-22 13 views
2

ブラウザの戻るボタンに関するいくつかの質問があります。ブラウザの戻るボタンと前のページのURL

1)私は現在のページに来た前のページのURLをどのように識別できますか? 2)リクエストがブラウザ履歴内の前のページのものであることを確認するにはどうすればよいですか? 3)ユーザーがブラウザの戻るボタンをクリックしたことをどのように知ることができますか?

ユーザーは、アプリケーションのある時点でアプリケーションの戻るボタンをクリックすると、エラーページに戻ります。

実装はjavasctiptを使用する必要があります。私は履歴オブジェクトを使って作業を試みましたが、今のところ私は打たれています。私を助けてください!!

答えて

1

1)はどのように私は、現在のページ

window.document.referrer 

リターンページが開かれた場所からのURLになってきた、それを通して、前のページのURLを識別することができます。ここでは他の二つの質問について

は、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. 
関連する問題