jQuery in Action, 2nd edition*
The moose likes HTML, CSS and JavaScript and the fly likes How to disable right click in a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to disable right click in a page " Watch "How to disable right click in a page " New topic
Author

How to disable right click in a page

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
I dont want allow the user to copy the content on the screen
so please tell me
How to disable right click in a page

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Modern day browsers will not let you do this and if they have JavaScript disabled than your protection does not work.

A google search will give you the answer. Bet solution is if you do not want people to take it, do not put it online.

Eric
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

They can always view the source or take a screenshot without right clicking anyway.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Rude and useless. Don't bother trying to work around it, you can't.

Also, please read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Pavan

Here it is, Simply Add the below script in the body section of your page this will disable the script. Anyway others can track the source using page source or screen shot.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I love seeing document.layers in code, makes me realize people are tyruing to support a 10 year old browser.

Eric
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
I accidentally uncovered a very easy way to do this during my first project in IT industry - as a fresher... and I just love it.
Type in this code in the <body> tag

<body oncontextmenu="return false;">


and enjoy the look on the user's face when he right clicks on the page
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
As said before, one can still grab the content by just disabling JS, or exploring the browser cache, or taking a screenshot.

Useless and rude. You should never try to change the client's environment/behaviour. Disabling the back button falls in the same story.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Dawn Charangat wrote:I accidentally uncovered a very easy way to do this during my first project in IT industry - as a fresher... and I just love it.
Type in this code in the <body> tag

<body oncontextmenu="return false;">


and enjoy the look on the user's face when he right clicks on the page


Try it in modern day browsers with default settings....

Eric
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249


You were right Eric.... It did not work in IE 7

But hey, it works just fine in Chrome 1.0.154.53 and Mozilla Firefox 3.0.7

[those are the only web browsers I have in my lappy.... so can I claim partial success ]

Dawn
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Dawn Charangat wrote: so can I claim partial success

Partial success is just another phrase for failure.

Hacks, especially those that only work on some browsers, are never a proper solution.
 
jQuery in Action, 2nd edition
 
subject: How to disable right click in a page
 
Similar Threads
disable view source menu
Disabling the short-cut(right) menu from the image.
overwriting methods
Back Button & Mouse Risk click
Disabling Right Click