1

新しい JS/HTML5historyメソッドをテストしています。サブページの読み込み時に、URL と履歴の状態を変更するイベントがあります。

$("#content").load("./content/map.txt", function() {
     history.pushState({}, "map", "map.html" );
     window.history.go(1);
});

ユーザーが [戻る] ボタンをクリックするhistory.stateと、URL が変更されますが、前のページは読み込まれません (現在の URL は更新されません)

変更に手動更新を追加しようとしましたが、次のhistory.stateようなものが見つかりました。

window.addEventListener('popstate', function(e){
     if (history.state){
         self.loadImage(e.state.path, e.state.note);
     }
}, false);

しかし、うまくいきません。

4

1 に答える 1

-1

これを試して:

window.onpopstate = function(event) {
  if(event.state["map"] == "some_state") // get the current state from the event obj
    location.reload(); // reloads the current page to clear ajax changes
};
于 2013-11-11T16:38:57.267 に答える