1

phonegapでJavaScriptを使用して前のページを取得するにはどうすればよいですか?

特定の html ファイルから来た場合にのみ戻りたい ( window.history.back())。そうでない場合は、戻るボタンが押されたときに別の html ページに移動したい。それで、歴史の前のページがどれか知りたいです。

私はしばらくグーグルで検索してきましたが、自分に合った答えが見つかりませんでした。

4

1 に答える 1

9

何か組み込みが必要な場合はdocument.referrer、以前の URL を取得するために使用できます。ただし、ニーズに対して信頼できない場合があります。詳細はこちらこちらこちら

もう 1 つの非常に簡単なオプションは、現在のページ名をセッション ストレージに格納し、それを読み取ってから、次に何をすべきかを決定することです。

//retrieve the previous page
var previouspage = window.sessionStorage.getItem("page"):
// if thee is no previous page you are on the first page
if (previousPage == undefined){
 //do something if you want, this means it's the first page the user is seeing
 }
//get current page address
var currentPage = window.location.href;
//store it
window.sessionStorage.setItem("page",currentPage); 
//check if the previous page is the one you wanted.
if (previousPage == "the_page_you_wanted"){
 // do something.
 }

LocalStorage と SessionStorage

于 2013-05-17T13:05:45.423 に答える