Disable the right click using javascript?
>> Monday, June 20, 2011
In this tutorial we are disabling the right click by using javascript
Copy the code and try it
When we use right click it appears like below image
Copy the code and try it
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="javascript"> var isNS = (navigator.appName == "Netscape") ? 1 : 0; if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP); function mischandler(){ return false; } function mousehandler(e){ var myevent = (isNS) ? e : event; var eventbutton = (isNS) ? myevent.which : myevent.button; alert("right is disabled due some security reasons"); if((eventbutton==2)||(eventbutton==3)) return false; } document.oncontextmenu = mischandler; document.onmousedown = mousehandler; document.onmouseup = mousehandler; </script> </head> <body> </body> </html>When we run the code it looks like below
When we use right click it appears like below image
0 comments:
Post a Comment