Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Body tag to disable right click

Status
Not open for further replies.

sqoti

Programmer
Dec 1, 2000
50
US
There is a onload event you can put in the body tag that will disable the right click option. I had it the other day, but accidently deleted it. It was something like

< body onload = ???????() = false;>

I think the event was something like config something.

Can anybody help?

Thanks in advance.
 
Sqoti,
Here is some Javascript that does something like you ask. FAR from foolproof however! :)
----------------------------------------------------------
<html>
<head>
</head>
<body>
<SCRIPT language=&quot;JavaScript&quot;>
<!--
var message=&quot;The right-click has been disabled on this page!&quot;;
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// -->
</SCRIPT>
Try clicking the right mouse button (works in IE5.x Dunno about other versions or NS)
</body>
</html>
 
sqoti,
if you would perform advansed search here on your subject you would get a lot of different interpretations of this script:

<script language=&quot;JavaScript1.2&quot;>
if(document.layers) document.captureEvents(Event.mousedown);

function nocontextmenu(){
event.cancelBubble=true
event.returnValue=false;
return false;}

function norightclick(e){
if(document.layers){
if(e.which==2||e.which==3)
return false;}
else
if(event.button==2||event.button==3){
event.cancelBubble=true
event.returnValue=false;
return false;}
}
document.oncontextmenu=nocontextmenu;
document.onmousedown=norightclick;
</script>

so, i think it is really good at doing its job :) Victor
 
Thanks for all your replys, but the body tag did the trick. Why would I want to do an advance search when I knew there was an easier way to do this? Tek-Tips is awesome. You guys Rock!!!!
 
becouse, as aperfectcircle wrote, that thing works in ie only
but looks like it is enough for you..
you're LUCKY !!!
:)

Victor
 
It is impossible to make it so no one can see your source code, unless ofcourse you make it, take a screen shot, create into one BIG image. No one could do it then :)

Most JS and HTML snipplets to prevent right clicking work in one browser only. However, you can ALWAYS view the source codes if you open your temp internet folder :) Just an FYI

-Acid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top