我试图阻止浏览器中的后退/前进按钮,但没有成功!任何帮助表示赞赏...
以下代码适用于我的本地系统,但不适用于服务器。
history.pushState(null, document.title, location.href);
window.addEventListener('popstate', function (event) {
history.pushState(null, document.title, location.href);
});
最佳答案
尝试警告用户而不是阻止,因为并非每个浏览器都支持此功能
使用以下代码警告用户
window.onbeforeunload = function() {
return "Are you sure ? work will be lost.";
};
关于javascript - 返回按钮在本地工作但在实时服务器上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43797381/