html 5 history restores some changes and not others?

纵然是瞬间 提交于 2019-12-05 21:06:05

The browser's history is just a list of URLs. pushState lets you associate an object with a URL in the history, a "state" if you will. This object is the 1st parameter passed to pushState.

Just like when browsing the history "normally", the actual state of the page isn't saved. That's up to you. In your object, you should save that the red box should be shown, and in onpopstate show it again.

Such as:

history.pushState({
    redBox: document.getElementById('box').style.display
}, 'Most browsers ignore this parameter.', '?complete=true');

Then in onpopstate, set document.getElementById('box').style.display to event.state.redBox.

EDIT: The iFrame is like a new browser window, so it has its own history object. When you click "back", the iFrame sees that and goes back in history. You need to have window.addEventListener('popstate', function() inside the page in the iFrame too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!