Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I stop users from highlighting text?

Status
Not open for further replies.

neillovell

Programmer
Aug 27, 2002
560
GB
Is it possible to stop users highlighting text on a webpage? you know, holding the left mouse button down and dragging across the text.
 
If it's possible, I think this is going to be very difficult. By the way, why do you want to do that ? Water is not bad as long as it stays out human body ;-)
 
You could use an image for presenting your txt - then you might to generate it on the fly - php and asp.net have things to do just that... This is not a bug - it's an undocumented feature...
;-)
 
Hi mate,

I am not saying that using this is right to use this, or even that it will work ok for what you want, but try adding the following to your body tag:

onFocus="window.blur()"

Hope this helps Wullie

sales@freshlookdesign.co.uk

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
My manager suggested it, though I thought it was impossible to do. You need to use combo boxes and buttons in this window also.

He got that error where you highlight, then you move the mouse and it's still in "highlight" mode even though the mouse button is up.
 
Hi mate,

If you need to use select boxes etc then that is a totally different situation. You could try adding the code to the blocks of text rather than the full page though.

As for the error, I don't know what you mean. The text will still highlight, but right clicking to copy etc, would de-select the text.

Hope this helps Wullie

sales@freshlookdesign.co.uk

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
If you are trying to keep your content from getting ripped, sorry. There is always a way around anything. Even if it was an image, I would probably use a image to text conversion program to jack it, if I were so inclined.
 
You can try this. <body onselectstart=&quot;return false&quot;>
 
Like someone said earlier, make an image, that's the only way to do it. Preventing left or right clicking won't do it since there's faults in that and the user can always do a source copy.

Either make an image or don't show text you don't want coppied.

sulfericacid

(interesting question though)
 
That is an option... but not everyone has a fast computer and probably wouldn't want to wait around for large images to load.
 
well just make a small transparent image 1 pixel by 1 pixel....then put it in a layer abover everything and make the layer 100% widht by 100% height and also make the image in the layer 100% by 100% and that way it will be a small image and wont take forever to download and will cover your whole page [soapbox]
sleep is good
 
Wow deecee that is a great tip (I assume it works!).

I've never come across onselectstart before, but I'll give it a whirl. Thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top