Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Disable Right Click of Mouse with Javascript

Posted by Viral Sarvaiya on June 8, 2009

Make one javascript file named “dm.js” and put below code into it.
********************************************
var omitformtags=[“input”, “textarea”, “select”]
omitformtags=omitformtags.join(“|”)
function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}
function reEnable(){
return true
}
if (typeof document.onselectstart!=”undefined”)
document.onselectstart=new Function (“return false”)
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
var message = “”;
function clickIE() { if (document.all) { (message); return false; } }
function clickNS(e) {
if
(document.layers || (document.getElementById && !document.all)) {
if (e.which == 2 || e.which == 3) { (message); return false; }
}
}
if (document.layers)
{ document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS; }
else { document.onmouseup = clickNS; document.oncontextmenu = clickIE; }
document.oncontextmenu = new Function(“return false”)
*****************************************

Write the below line in your head section of your file.

<script src=”FrontJs/dm.js” language=”javascript” type=”text/javascript”></script>

Now Your Page is Right click protected for text and image even you can not select the text from your web page.

Advertisements

One Response to “Disable Right Click of Mouse with Javascript”

  1. thebozzman said

    A good post, but I think before you disable the right-click of a user’s browser, you ought to give some thought to the pros and cons of doing so: http://thebozzman.wordpress.com/2011/03/20/to-disable-right-click-or-not-to-disable-right-click/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: