状态对象是一个 JavaScript 对象,它与 pushState() 创建的新历史记录条目相关联。
https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState()_method
在Chrome开发工具中,是否可以检查此状态对象的内容?
https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState()_method
在Chrome开发工具中,是否可以检查此状态对象的内容?
state
对象是 history
对象的一个属性。您可以在控制台中使用以下内容访问它:
window.history.state
var back = window.history.back;
window.history.back = function() {
console.log("location: " + document.location + ", state: " +
JSON.stringify(window.history.state));
return back.apply(this, arguments);
}
history.pushState({page: 1}, "title 1", "?page=1");
history.pushState({page: 2}, "title 2", "?page=2");
history.pushState({page: 3}, "title 3", "?page=3");
history.pushState({page: 4}, "title 4", "?page=4");
window.onpopstate = function(event) {
console.log("location: " + document.location + ", state: " +
JSON.stringify(event.state));
};
history.pushState({page: 1}, "title 1", "?page=1");
history.pushState({page: 2}, "title 2", "?page=2");
history.pushState({page: 3}, "title 3", "?page=3");
history.pushState({page: 4}, "title 4", "?page=4");
这个第二个例子没有记录当前状态,所以你首先要记录一下。
出于安全原因,不可能查看历史记录堆栈。
popstate
示例。 - djvg