我正在尝试使用History API并遇到了一个无法解决的问题。将一个新状态推送到api后,我无法在window.history.forward()上模拟popstateEvent(模拟浏览器前进按钮的点击)。使用window.history.back()一切都按预期工作。我想知道为什么会发生这种情况。这是为了吗?
window.onpopstate = function(event) {
console.log(event);
};
window.history.pushState({'state': 'test'}, '', '/testurl');
window.history.go(1);
window.history.back();
window.onpopstate = function(event) {
console.log(event);
};
window.history.pushState({'state': 'test'}, '', '/testurl');
window.history.go(1);
window.history.forward();
资源:
尝试浏览器: 最新的FireFox Quantum Beta 最新的Google Chrome稳定版