我有一个用户可以打开作为模态窗口的表单。我希望能够检测到他们何时浏览并关闭窗口。
我已经开始工作但是有一些问题:
// in modal.open():
window.history.pushState(null, null);
// in modal.close():
window.history.back();
这可以解决它们可以向前浏览并且没有任何反应的副作用......这是一个边缘情况,它可能无关紧要,但它困扰我。
浏览时如何“擦除”当前状态?所以他们无法前进。
答案 0 :(得分:0)
https://jsfiddle.net/5y6jL0an/
history.pushState(null, null, 'no-back-button');
window.addEventListener('popstate', function(event) {
history.pushState(null, null, 'no-back-button');
});