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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping text selection in Firefox 1

Status
Not open for further replies.
Dec 8, 2003
17,047
GB
I found an interesting CSS property today, while searching for a way to make text unselectable in Firefox.

In IE, it is fairly simple... either add:

Code:
unselectable="false"

to an element, or use JavaScript:

Code:
el.onselectstart = function() { return(false); };

Unfortunately, Firefox supports neither of these methods. It does, however, support one of the proposed CSS3 properties, "user-select".

Because the specifications have not been finalised, it needs to be accessed by it's "pre-release" name, "-moz-user-select".

Anyway, to stop text being selectable in FF, and any future browsers that support the property, you can use:

Code:
selector {
   -moz-user-select: none;
   user-select: none;
}

I've just found this very useful... hope someone else does, too.

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Uncanny, I came across that property yesterday too. What irritates me about these [tt]-moz[/tt] properties is that there seems to be no documentation about them - I spent ages trawling through the various Mozilla sites looking for a list of them. At least when M$ add a non-standard property they document it in MSDN somewhere.

Eventually I came up with this unofficial (and seemingly rather old) page that lists several Mozilla extensions:


Anyone got a better one?

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
With Google, you cannot just search for:

Code:
-moz-user-select

as I believe it takes that to mean any document without the words "moz", "user", and "select" (and thus no results are returned because there is no positive search criteria). You have to wrap it in quotes to pick up anything:

Code:
"-moz-user-select"

Then you get a whole bunch of results back, including your page, and the one I found:


Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top