Forum Moderators: open
I know all the negative publicity disabling right click has...be that as it may there is a good reason I want to try this:
I would like to be able to disable right clicking on only a certain part of a web page, say between two div or span tags. How would one go about this and is there some example code floating around?
Thank you in advance,
Ron
<html>
<head>
<title></title>
<script language="javaScript" type="text/javascript">
<!--
// note, this script doesn't work with Opera yet.
NS4 = document.layers? 1 : 0;
function block(){return false;}
function noKey(e) {
if(NS4){
if (e.keyCode == 96){ return (false);}
} else {
if (event.keyCode == 96){ return (false);}
}
}
function disable(e){
if(NS4){
return false;// found a ns4 bug here: if(e.which > 1) {return false;}
} else {
if(event.button > 1){return false;}
}
}
function block_right_click( elementID )
{
if(NS4){
document.captureEvents(Event.MOUSEDOWN);
}
document.getElementById( elementID ).oncontextmenu = block;
document.getElementById( elementID ).onkeypress = noKey;
document.getElementById( elementID ).onmousedown = disable;
document.getElementById( elementID ).onmouseup = disable;
}
// -->
</script>
</head>
<body>
<div id="norightclick" style="height:300px;background-color:blue;" onmouseover="block_right_click('norightclick');"></div>
<div style="height:200px;background-color:green;"></div>
</body>
</html>
<script language=Javascript>
function mousedown(evt)
{
evt = (evt)? evt : ((window.event)? window.event : "")
if (evt)
{
var clickType=1;
if (navigator.appName=="Netscape") clickType=evt.which;
else clickType=evt.button;
if (clickType==1) { return true; }
}
return false;
}
</script>
<div id=noClick onMouseDown="mousedown();"></div>