开发者

Removing an event handler by setting null is not working in Firefox 3.6

开发者 https://www.devze.com 2023-02-05 09:08 出处:网络
I was experimenting this code. It worked well in Chrome but not in Firefox 3.6 <body onmousedown="return false" oncontextmenu="return false">开发者_运维技巧

I was experimenting this code. It worked well in Chrome but not in Firefox 3.6

<body onmousedown="return false" oncontextmenu="return false">开发者_运维技巧
<p>once there lived</p>
<div style='color:red; height: 300px; width:100%;'>
hehe</div>

<script>
/*
window.setTimeout( function() {
     document.body.onmousedown = function() { return true; }
     document.body.oncontextmenu = function() { return true; }
     document.onmousedown = function() { return true; }
     document.oncontextmenu = function() { return true; }
     alert('ready to check');
},5000)
*/

window.setTimeout( function() {
     document.body.onmousedown = null;
     document.body.oncontextmenu = null;
     document.onmousedown = null;
     document.oncontextmenu = null;
     alert('ready to check');
},5000)

</script>
</body>


In Gecko-based browsers <body onmousedown> maps to window.onmousedown, not document.onmousedown or document.body.onmousedown. On other elements the mousedown element maps to the mousedown property as expected.


I'm pretty sure that should be working. Firefox has an option to not allow JavaScript to disable/replace context menus -- perhaps you have that set?

0

精彩评论

暂无评论...
验证码 换一张
取 消