views:

1008

answers:

7

Hi All, Can I disable right click on my web page without using javascript because most of the browser allow the user to disable javascript.

+4  A: 

You cannot accomplish what you're asking without using Javascript. Any other technology you may choose to use can only help to compose the web page on the server side to be sent to the browser.

There simply is no good solution, and there is no solution period without Javascript.

Tony k
And even then its annoying for the users, not to mention easy to bypass.
Manos Dilaverakis
I've only ever seen pages which have a modal popup saying 'right click is disabled', which then shows the right-click menu when you dismiss it. They also display the message when you scroll using trackpad, which is very annoying.
Pete Kirkham
Yea, it's especially annoying since usually it's to prevent people from "stealing" images which are already on their harddrive, but all it does is prevent me from using Context Search: https://addons.mozilla.org/en-US/firefox/addon/240 . Those bastards...
Calvin
+6  A: 

You can do so with Javascript and/or an HTML attribute (which is really a Javascript event handler anyway) as described here:

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
  if(event.button==2)
   {
     alert(status);
     return false;    
   }
}
</script>

and

<body oncontextmenu="return false">
...
</body>

That being said: DON'T DO IT.

Why? Because it achieves nothing other than annoying users. Also many browsers have a security option to disallow disabling of the right click (context) menu anyway.

Not sure why you'd want to. If it's out of some misplaced belief that you can protect your source code or images that way, think again: you can't.

cletus
its not really "javascript or html" , its only really "and", as the "html only" way will require javascript, which if is not available/disabled, will not run.
Kent Fredric
( I know what you're saying, but its not 100% clear )
Kent Fredric
thanx a lot very clear instructions.................
Vinay Pandey
+7  A: 

First, you cannot achieve this without using a client side capability. This is where the javascript runs.

Secondly, if you are trying to control what an end user can consume from your site, then you need to rethink how you display that information. An image has a public url that can be fetched via HTTP without the need for a browser.

Authentication can control who has access to what resources.

Embedded watermarking in images can prove that the image was from a specific person/company.

At the end of the day, resource management is really user/guest managment.

The first rule of the Internet, if you dont want it taken, dont make it public!

The second rule of the Internet, if you dont want it taken, dont put it on the Internet!

Wayne
+28  A: 

DON'T

Just, don't.

No matter what you do, you can't prevent users from having full access to every bit of data on your website. Any Javascript you code can be rendered moot by simply turning off Javascript on the browser (or using a plugin like NoScript). Additionally, there's no way to disable the ability of any user to simply "view source" or "view page info" (or use wget) for your site.

It's not worth the effort. It won't actually work. It will make your site actively hostile to users. They will notice this and stop visiting. There is no benefit to doing this, only wasted effort and lost traffic.

Don't.

Wedge
+2  A: 

If your aim is to prevent people being able to download your images, as most people have said, disabling right click is pretty much ineffective.

Assuming you are trying to protect images the alternative methods are -

Using a flash player, users, can't download them as such, but they could easily do a screen capture.

If you want to be more akward, making the image the background of a div, containing a transprent image, a la -

<div style="background-image: url(YourImage.jpg);">
   <img src="transarent.gif"/>
</div>

will be enough to deter the casual theft of your images (see below for a sample), but as with all these techniques, is trivial to defeat with a basic understanding of html.

benophobia
A: 

Of course, as per all other comments here, this simply doesn't work.

I did once construct a simple java applet for a client which forced any capture of of an image to be done via screen capture and you might like to consider a similar technique. It worked, within the limitations, but I still think it was a waste of time.

Cruachan
A: 

Can I just say - you all say don't do it because it annoys users - as the only people likely to right click on your pictures are actually stealing the photos (Or taking them to use without permission and breaking copyright in the first place) then you should really rephrase your answers as "it only annoys the thieves".

Photographers spend a lot of time fighting for the right to protect their art (This isn't the multi-million music industry that rips off fans and then complains about the downloading they are, ultimately, responsible for) such as defeating the recent UK legislative clause aimed at allowing companies to use, free of charge, so called 'orphan images'. We are talking about photographers from professionals down to the talented amateurs who make a few pennies from their art and who deserve not to be robbed. It sometime takes hours to produce a great picture so why should anyone have the right to steal it off someone's webpage? After all the majority of people walking through the Tate Gallery aren't annoyed by the security their as they aren't there to steal the artwork, just look at it.

I see the only way around this is to put a legal notice on their site that if any images appear anywhere without permission then the person displaying that image will be sued for a substantial amount. After all the photographers have the originals and the copyright so the law is on their side 100%.

I would advise that, if you can't put a right click on the items you want protected, then protect them in the far more agressive, but ultimately more expensive for the thief, court route.

If I put a no right click on my images and it annoys people then I don't want those people on my site.

Richard