views:

104

answers:

4

I want to inactive selecting & copying text in html page. when I used Javascript & inactive right click user can use Ctrl+V!!

+3  A: 

There is no full proof solution. You can play javascript games (easy to turn off). You can place invisible layers about the text so it can't be selected easily (easy to view source). You can use images instead of text (just bad).

colithium
Full proof solution = Do not put it online. :)
epascarello
A: 

Try this:

http://codesnippets.joyent.com/posts/show/515

AlbertoPL
It's important to note that the user can simply turn off Javascript, but this will work for those that do not.
AlbertoPL
It's only going to annoy people, I advise against even trying. Seriously.
colithium
+6  A: 

You can't. Don't even try. Don't annoy your users.

If you put it publicly on the web, it can be copied. Technically, it already is copied as soon as the user sees it. As colithium pointed out, all the techniques can be circumvented. Heck, you can look at the source code. You can curl the raw data from the command line, no JS/IMG/layer hack can prevent that.

deceze
A: 

While I agree in principle with the other posters that trying to do this may annoy the user, sometimes a manager or customer demands that this be done, and so an answer needs to be supplied.

Check out this page on www.dynamicdrive.com that will supply you with a few JavaScripts towards this end. Specifically see "Disable Text Select Script" and "No right click script".

Bork Blatt
It would be better to explain to the manager or customer why it is a very bad idea to try to prevent this.
Sander Marechal
True - and this is the approach I try - but sometimes they put their foot down, and then you have no choice.
Bork Blatt
Sander: It is not a bad idea at all. For example, if it is against the EULA/TOS to copy this text to outside contexts, then making it _difficult_ to do puts the onus on the abuser. It is like locking your front door (or at least closing it). Of _course_ it does not prevent burglary -- but it creates a definite barrier against the lazy or amateur thief and removes any possible dispute or confusion about the appropriateness of entering your home.
larson4