Making Text Unselectable

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have several pieces of text that I do not want to be selected/highlighted
(they are things such as individual X's on buttons and such that are there
more for decoration rather than text). I could not find any CSS properties
that do this, and I'm not sure where to look other than CSS. Any ideas?
 
Hi Nathan,

onselect="javascript:return false;"

place your unselectable text within a <span> and assign the above event to
the span.
Don't forget to test if the client has scripting enabled <noscript>"You must
have scripting enabled to use this page.... </noscript>

PS. I think the event is onselect or it could be onselectstart..

Regards.
 
That works great when the user starts the selecting from withing the span
tag, but they can still select the text by starting their selecting from
outside of the span tag. Any other ideas? Thanks.
 
Jon Kennedy said:
You can do it via scripting:
http://www.dynamicdrive.com/dynamicindex9/noselect.htm - note how you cannot
select text on that page, too (page is it's own demo).


But they do leave it cached and don't even disable View Source


I'm glad that the responders try to point out the ultimate futility of the exercise.



Ctrl-a,Ctrl-c captures that.


---
 
Hi Nathan,

Try placing nested spans with selection turned on or off as required or

Turn selection off for the document body and place spans around the text
that you do want to allow selection on with selection enabled.

Don't know what you are trying to stop users from doing? Its almost
impossible to stop a determined hacker from gaining a copy of your html
source.

Regards.
 
My reason for trying to stop selection is not for security, it is for
appearance reasons. An ASP.NET control that I made, which uses a table with
an X in the two cells at the left and right ends, looks somewhat
unattractive if it is highlighted, and we all know how easy it is to
accidentally highlight something. Therefore, I want to create the ability to
have the mouse dragged over it without highlighting these X's. I would be
perfectly willing to give people my HTML code.
 
All the ideas I noticed seemed to be concentrating on making the whole page
unselectable, I am worried about just a tiny area (a small table that has 2
characters and 1 nonbreaking space in it, most people wouldn't even think
about selecting it). I also have access to only the properties of this
table, since this is a server-side control I will be sharing with other
people, so I don't know what any of the page other than this will look like.
 
Back
Top