Browser 如何禁用浏览器的后退、前进和刷新按钮?
我想禁用浏览器的导航按钮:后退、前进和刷新。这是为使用with jQuery进行测验的学生准备的 我尝试了以下代码,但不起作用:Browser 如何禁用浏览器的后退、前进和刷新按钮?,browser,Browser,我想禁用浏览器的导航按钮:后退、前进和刷新。这是为使用with jQuery进行测验的学生准备的 我尝试了以下代码,但不起作用: window.history.forward(); function preventBack() { window.history.forward(1); } function disableBackButton() { window.history.forward(); } setTimeout("disableBackButton()", 0); 在do
window.history.forward();
function preventBack() { window.history.forward(1); }
function disableBackButton() {
window.history.forward();
}
setTimeout("disableBackButton()", 0);
在document.ready上使用此行
window.history.forward(-1)
希望它能工作你不能。这将允许网站所有者劫持用户的浏览器。想象一下,如果你被困在一个无法离开的页面上。如果用户想要离开、刷新或关闭选项卡,浏览器必须允许这种行为 也就是说,你可以做类似的事情
$(window).on('beforeunload', function () {
$.ajax('/mark-the-user-as-failed') // you may not get the response
return 'You are not allowed to leave or refresh the page. This attempt has been logged.'
})
但是,这也会在表单提交时触发(也称为合法请求),因此您需要通过删除处理程序或使用信号量变量来处理这些情况 你能提供你写的代码吗?考虑一下:请再次检查问题,我在那里替换代码。