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.
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.
Share Improve this question edited Jan 15, 2009 at 11:39 WishKnew asked Jan 15, 2009 at 10:47 WishKnewWishKnew 6592 gold badges10 silver badges22 bronze badges 3- Why would you want to do this? – innaM Commented Jan 15, 2009 at 10:51
- Please do not do that. It's bad enough I can't select text in Flash sites. – OregonGhost Commented Jan 15, 2009 at 10:55
- 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. – WishKnew Commented Jan 15, 2009 at 11:07
7 Answers
Reset to default 15Render 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! ;-)
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.
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.
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.
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.
Google books seems doing a good job on preventing copying text/image content. I've no idea how they achieve that, though.
You could also render the text to an embedded flash object. This is a fairly simple technique that is used commonly for blog templates