shm*_*nsw 9 javascript jquery pushstate popstate
是否有可能将最后一个状态的html推送到历史堆栈,如下所示:
history.pushState(null, null, {html: $('body').html()});
Run Code Online (Sandbox Code Playgroud)
更改窗口位置:
window.location = url;
Run Code Online (Sandbox Code Playgroud)
现在从新的位置:
window.addEventListener('popstate', function(event) {
// back to the last state - event.state.html
}
history.back() // That what's firing the popstate event?
Run Code Online (Sandbox Code Playgroud)
我搜索了获取推送到历史记录的最后状态的html的请求,但没有得到满意的答案。但我有一个想法给你,你为什么不尝试在将状态推送到历史之前保存 html 呢?使用客户端(cookie)或服务器端(会话)变量很有可能实现这一点,即使在事情被推回到历史记录之后也可以检索这些变量。