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?
精彩评论