View Full Version : disable right click


designhazard
05-15-2003, 08:12 AM
does anyone know how to disable my web page from right clicking without an alert?

J E P P O
05-15-2003, 08:29 AM
here:


<script language="JavaScript">



if (window.Event)

document.captureEvents(Event.MOUSEUP);



function nocontextmenu()

{

event.cancelBubble = true

event.returnValue = false;

return false;

}



function norightclick(e)

{

if (window.Event)

{

if (e.which == 2 || e.which == 3)

return false;

}

else

if (event.button == 2 || event.button == 3)

{

window.event.cancelBubble = true

window.event.returnValue = false;

return false;

}

}



document.oncontextmenu = nocontextmenu;

document.onmousedown = norightclick;

</script>


add this 2 ur <head> </head>

Cheers

designhazard
05-15-2003, 08:31 AM
thanks! that works!

pb&j
05-15-2003, 11:46 AM
remember of course... file, view, source will still work.
non-right click is a very low security for anything.

designhazard
05-18-2003, 04:09 AM
yeah, i know.

SSPrincess
05-18-2003, 07:37 PM
So true. However, there is a code to stop people from doing file, view, source and right click as well. However not even that is fool proof, only copyrighting your stuff will. Anyway here's the code to stop both right clicking and the view source:

<script language="JavaScript1.2">
//original author unknown
//modified by, and displayed on www.a1javascripts.com
if (window.Event)
document.captureEvents(Event.MOUSEUP);

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

return false;
}

function norightclick(e)
{
if (window.Event)
{
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;
}

}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.oncontextmenu = nocontextmenu;
document.onmousedown = norightclick;
document.onmouseup = norightclick;
//-->
</script>

rundellt2000
05-24-2003, 02:19 AM
I tried the no-source script. That didn't work. Maybe it's because I have a newer browser...

SSPrincess
05-24-2003, 02:27 AM
I think that's the problem, because it works just fine on my old computer, but not on my new computer. I'll have to find something that does.