views:

1393

answers:

8

Dear All,

I need to prevent user from selecting text (select all or select a portion of text) in the browser Mozilla Firefox, using java script. I have done this using Internet Explorer, but it seems doesn't work with Mozilla.

Any hints? URL? Sample?

TIA.

EDIT:

Actually, this ridiculous problem was requested by our client. And yes, we have explained them that there are thousand other ways to get the text. But they answer that they know about that, they just want to prevent for amateur user to do that.

I have done some googling and find similar problem with the solution here.

+14  A: 

Render the text to an image if you really want to prevent people from copy-pasting it. Javascript tricks can always be disabled and/or worked around.

Of course the best way to prevent people from copying text is to not show it at all - they might read it and retype! ;-)

Simon Groenewolt
This is the best answer although I might add that OCR tools (MS OneNote for example) can read text on images very easily nowadays.
Chris Simpson
I don't think you'll ever be able to stop it completely... this is definately the best answer, and Chris just reminded me of a OneNote feature i completely forgot about..... (off to enable text in image searching now...)
GordonB
+2  A: 

Not possible, as far as I know.

Also, the user can always disable Javascript from the options page. So you cannot really rely on using Javascript to protect your data.

Both in IE and Firefox, the user can choose to view the source of the HTML page.

moogs
A: 

Google books seems doing a good job on preventing copying text/image content. I've no idea how they achieve that, though.

PolyThinker
+2  A: 

I can only advise against trying to stop the user from selecting text on a website. Users who want to copy the text with a bad intent will always find a way, but you will anger the users who only want to copy a link or who want to copy some text to paste it comfortably into a search box.

Sebastian Dietz
I disagree. There are plenty of users who want to get ahold of the text for prohibited use that are not technical enough or motivated enough to actually figure out how.
larson4
A: 

There is no way to fully protect content you publish, short of DRM schemes which are not widespread enough to be useful for a website. But to prevent simple copy-and-paste there are several approaches, each of which is very annoying to your users.

A simple way would be to cover the text with another element, such as a DIV, using CSS positioning. This would mean that when the user tries to click on the DIV to select the text there would be no text to select. Should work in any browser that supports CSS and in browsers that don't it will probably be completely invisible. Clicking on the page and hitting CTRL-A (or some other shortcut key) may select the text anyway, and it may be impossible to block all key and mouse events that can get at the text. But this DIV "lid" approach is at least unobtrusive and easy to generalize. However, this is trivially defeated by looking at the HTML source. It is less trivially defeated by turning off CSS (easy to do in Firefox, and many Firefox users are sophisticated enough to do it).

A more robust approach would be to render the text as a graphic, either using a regular image file or something like a PDF. However graphics can be OCR'ed. There are free tools for this.

Finally you could put your text in a Flash or Java applet, which would download the text from the server. Someone could steal your applet but would have difficulty making it talk to your webserver due to the same-origin security policy (note: this can also be worked around). This approach is not that much better than the PDF approach except that it makes it harder to grab entire documents, because the applet will only display a portion of the document at a time. To defeat this using OCR the attacker has to take screen-captures. Or they could reverse-engineer your applet and make a new applet (or even a regular program) which downloads all the content from your server.

All those approaches are only of the most basic use and I suspect you'll find that they don't help at all. You'd probably get more return on investment building useful features rather than this.

Mr. Shiny and New
A: 

You could also render the text to an embedded flash object. This is a fairly simple technique that is used commonly for blog templates

Conrad
A: 

do not show it

+1  A: 

Why does everyone assume that the purpose of preventing selection must be because you want to protect the text. What if the test is someplace in your UI where there's no need to copy the text and accidental selection is just annoying.

amen brother! exactly right
larson4