Is there user-select for Opera 10.62 and IE9?
Asked Answered
C

5

11

I have been trying to apply user-select for both Opera 10.62 and IE9 without success. I can't/won't bind events with JavaScript that preventDefault(), because there are so many places to be set unselectable and I still need to retain selections in several places. In fact, I want the default behavior to be unselectable for the whole document, and as for that I have set the following in my stylesheet:

* {
    -o-user-select: none;
    -webkit-user-select: none;
    -moz-user-select: -moz-none;
    -khtml-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

Everything works great with Firefox 4, Chrome 7 and Safari 5. Only IE9 and Opera 10.62 are not working as I would like them to. Any ideas?

PS: I'm targeting modern browsers.

Cliffcliffes answered 10/10, 2010 at 14:58 Comment(1)
See: #827282Matrilocal
N
7

Did you try using ::selection {color:currentColor;background:transparent}?
For Firefox you can use ::-moz-selection.

https://developer.mozilla.org/En/CSS/::selection
http://msdn.microsoft.com/en-us/library/ff974109(v=VS.85).aspx
http://reference.sitepoint.com/css/pseudoelement-selection


// update //
There's also the unselectable property.
Nauseate answered 10/10, 2010 at 20:51 Comment(8)
Yeah, but that's not really good because it just hides the selection. You can still drag the selection and copy it.Cliffcliffes
check my update - and read developer.mozilla.org/en/CSS/-moz-user-select "Controls the appearance (only) of selection. This does not have any affect on actual selection operation."Nauseate
A combination of the -user-select properties and unselectable worked a treat for me cross-browser.Chopine
Shouldn't color: currentColor be color: inherit?Varicotomy
@Varicotomy you want the current color of the element (not of one of his ancestors).Nauseate
Ah ok, I learned something new today: I didn't knew there is the currentColor keyword.Varicotomy
If suppose there is a span in a div, and the div has a gradient as a background color, will this still work for the text inside the span?Freedom
disable user-select with CSS will not work in IE 8 & 9Greenbrier
T
4

You can use combination of -webkit-user-select: none;, -moz-user-select: none; and specific property unselectable="on", as I described here:

How to make text unselectable on HTML page

Tardif answered 11/3, 2011 at 15:47 Comment(0)
F
2

user-select isn't a standard CSS3 property, which is why there is no user-select or -o-user-select or -ms-user-select. It used to be in the old user interface spec, but that was superseded by the Basic UI spec. It will likely never be implemented by either browser, unless it is added back to the spec.

User selection is a behaviour rather than a style, so it is best to use JavaScript. As Knu mentions above, you can use unselectable instead.

Felicitation answered 12/1, 2011 at 19:43 Comment(5)
But what's awful is that children do not inherit unselectable. So, I would need to apply that for pretty much everything, manually. I have a application with text here and there, and by default I want everything unselectable. Only when I specifically want selections, I will define them. This approach is not implementable with unselectable. Also, the property works if you begin the selection on that element. Ctrl + A, etc. will work with unselectable.Cliffcliffes
Actually Opera does have -o-user-select. Not sure which version but I think 10.6 had it.Telles
@Tim Down: I'm pretty sure Opera doesn't support -o-user-select. It isn't listed in our spec opera.com/docs/specs/presto29/css/o-vendor and it doesn't show up in Opera Dragonfly either.Felicitation
@dstorey: A quick test would suggest you're right: jsfiddle.net/MguY2. I did test this a while ago and thought it was supported, but it seems I was wrong.Telles
-ms-user-select exists in IE10. Not 9.Caines
P
0

Using jquery:

$('.element').mousedown( function(e) {
    e.preventDefault();
});

But you may have to add it both to the element and it's container.

Phallus answered 4/7, 2013 at 22:34 Comment(0)
O
0

-ms-user-select: none;

seems to work fine now (IE 10/11)

Origan answered 26/12, 2013 at 20:20 Comment(1)
Wow! I thought IE11 was supposed to support the official standards without the need for browser specific hacks! When they introduced support for this, why not go directly on the standard without browser prefix ??!!! (And yes - I tested in IE 11; it only works with the -ms- prefix)Kummerbund

© 2022 - 2024 — McMap. All rights reserved.