Jump to content
xisto Community
wannabeeaweak

Javascript: Disable Mouse Right-click In Browser

Recommended Posts

Don't forget about the PrintScreen button on your keyboard.Disabling right-click could be useful, but it won't protect your images.
Put in a water-mark and maybe decrease the resolution to a preview edition to protect your images.

Yes that's the way to go to protect images. But nowadays you've got to put the watermark in the very middle of the picture, since it's very common to have people cropping the original picture to remove watermarks from the borders and alike.
A clear example of it is the watermark option in DeviantArt. It's huge, it's very noticeable and right in the image center. It's actually awful to look at that, since it kind of screws the picture mood, but in the case of having constant problems, it's the only way to go.

Share this post


Link to post
Share on other sites

Another way for disabling the mouse right-click is by using the oncontextmenu event, if you add this javascript code:

<body oncontextmenu="return false">
to the body tag, you disable the context menu that appears whenever you right click in your page.

For protect your images you can use another image that covers the one you want to protect or a div that covers all your page (located in front of your page) like:
<div style="width:100%;margin:0px auto;z-index:10;top:0px;left:0px;background-color:transparent;height:100%"><img alt="image alt text" src="imagename" ></div>
And of course, you can use the imagetoolbar meta tag, this one will not protect your images, it simply disallow the image toolbar of Internet Explorer and Firefox:
<meta http-equiv="imagetoolbar" content="no">
Best regards,

Share this post


Link to post
Share on other sites
easy stop right click - right click browser backJavascript: Disable Mouse Right-click In Browser

add this to the body tag: oncontextmenu="window.History.Go(-1);return false"

The user is sent back a page whenever they right click on your page.Though its tempting to replace the window.History with window.Close, it will cause a popup in IE.

Share this post


Link to post
Share on other sites
Thanks TavoxPeru --- It is Really helpful Javascript: Disable Mouse Right-click In Browser

I was having problem of disabling right click while doing multibrowser compatibility.But the solution provided by "TavoxPeru" it very helpful for me and get my job done.

Thanks Again

-reply by Ashwini

Share this post


Link to post
Share on other sites

Hi , kinda new so if you don't understand i don't blame you ;) I' have been reading you comments and as such i know i think heres what i gotPaste this under your <body> Im your html code

<div style="margin:auto; width:100%;">	<script src="Enter your file location here" type="text/javascript"></script><div class="topbg">

Now for the main code with you save as what ever name you want as long as it is .js (Javascript)

var message="Function Disabled";   //edit this message to say what you wantfunction clickIE() {	if (event.button==0) {alert(message); return false;}}function clickNS(e) {	if (document.layers||(document.getElementById&&!document.all)) 	{		if (e.which==2||e.which==3) 		{			alert(message);return false;		}	}}if(window.navigator.appName=="Netscape"){	document.onmouseup=clickNS;	document.oncontextmenu=clickIE;	document.oncontextmenu=new Function("return false")}else if (window.navigator.appName=="Microsoft Internet Explorer"){	document.oncontextmenu=clickIE;}else if (window.navigator.appName=="Opera"){}else if (document.layers) {	document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}else{	document.onmouseup=clickNS;	document.oncontextmenu=clickIE;}//

Then save it as your selected location then you can right click on your web site ;)

Edited by Brutal Art (see edit history)

Share this post


Link to post
Share on other sites
How i dosable right click on fireFox browserJavascript: Disable Mouse Right-click In Browser

Hi

I want to disable right click on my photo gellary. Your script work in IE perfectly but doesn't Firefox. Please help me

-reply by chrome

 

Share this post


Link to post
Share on other sites

The smallest piece of code is the oncontextmenu="return false;" thing, which you can really use if you want to.But there is no point in disabling right click because there are many ways to view the HTML, CSS and images of your have if they really want. View source, save page, use the W3C validator, there are many ways.To really disable right click, you can design your entire website in Flash, but that is likely overkill. And I can still take a picture by pressing Print Screen.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.