Showing posts with label Right-click. Show all posts
Showing posts with label Right-click. Show all posts

Thursday, May 31, 2007

How to prevent right-click with JavaScript

I have searched the web for this solution. I dont' remember where I found it but here is. This code disables right-click through JavaScript. Place it in the "head" section of your web page. The code works with Internet Explorer and Firefox.

<script language="javascript">

var isNS = (navigator.appName == "Netscape") ? 1 : 0;

if(navigator.appName == "Netscape")

document.captureEvents(Event.MOUSEDOWNEvent.MOUSEUP);

function mischandler( )
{ return false; }

function mousehandler(e)

{

var myevent = (isNS) ? e : event;

var eventbutton = (isNS) ? myevent.which : myevent.button;

if((eventbutton==2)(eventbutton==3))
return false;

}

document.oncontextmenu = mischandler;

document.onmousedown = mousehandler;
document.onmouseup = mousehandler;

</script>



Refer your friends to this blog:
http://programmingcentral.blogspot.com/