这是之前有效的代码,但现在不再有效。有谁知道为什么?
document.onkeydown = function()
{
if(event.keyCode==116) {
event.keyCode=0;
event.returnValue = false;
}
}
// To avoid refresh, using context menu of the browser
document.oncontextmenu = function() {event.returnValue = false;}
最佳答案
您在函数中引用了事件
,但您从未真正传递它:
document.onkeydown = function(){ /* ... */ }
document.oncontextmenu = function() {event.returnValue = false; }
// should be
document.onkeydown = function(event){ /* ... */ }
document.oncontextmenu = function(event) {event.returnValue = false; }
在 oncontextmenu 的第一个版本中,您将对象“event”的“returnvalue”设置为 false,但它不存在,因为您从未真正将其传递给函数。
关于javascript - 阻止 F5 刷新在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46604443/