我正在测试新的 JS/HTML5 history
方法。在子页面加载时,我有一个更改 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);
但它不起作用。
最佳答案
试试这个:
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
};
关于javascript - 如何刷新历史记录的页面。状态更改(单击后退按钮时)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18528751/