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”]
function disableselect(e){
if (omitformtags.indexOf(
return false
function reEnable(){
return true
if (typeof document.onselectstart!=”undefined”)
document.onselectstart=new Function (“return false”)
var message = “”;
function clickIE() { if (document.all) { (message); return false; } }
function clickNS(e) {
(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.


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:

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: