是否有可能将最后一个状态的 html 推送到历史堆栈,如下所示:
history.pushState(null, null, {html: $('body').html()});
更改窗口位置:
window.location = url;
现在从新位置开始:
window.addEventListener('popstate', function(event) {
// back to the last state - event.state.html
}
history.back() // That what's firing the popstate event?
最佳答案
我搜索了获取推送到历史的最后状态的html的请求,但没有得到满意的答案。但我有一个想法给你,你为什么不在将它插入历史之前尝试保存状态的 html?这很可能使用客户端(cookie)或服务器端( session )变量,即使在历史中的事情被推回之后也可以检索这些变量。
关于javascript - 从历史中弹出最后一个状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29706816/