12

I have the following CSS:

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

This works in every browser except for in IE, why is this? The selection of text looks really ugly because my menus are created from text and CSS... any ideas?

Freesnöw
  • 30,619
  • 30
  • 89
  • 138
  • 1
    possible duplicate of [css rule to disable text selection highlighting](http://stackoverflow.com/questions/826782/css-rule-to-disable-text-selection-highlighting) – Tomalak May 23 '11 at 17:33
  • @Tomalak I don't think this is a duplicate. That question asks "What's the CSS?", while this one starts with the CSS and asks how to work around it for IE. As I already knew the CSS3 but need to find a fix in IE6-9 I found this question a lot more useful than the other. – Keith Jan 23 '14 at 10:26
  • This question has been answered: https://stackoverflow.com/questions/826782/css-rule-to-disable-text-selection-highlighting – Naveed Ahmad May 23 '11 at 17:32

2 Answers2

26

You can use Javascript and do:

document.onselectstart = function() { return false; }
document.onmousedown = function() { return false; }

The first one works for IE and the second one does Mozilla-based browsers.

Justin
  • 1,956
  • 3
  • 23
  • 34
  • 1
    What if you want to prevent selection within a single element? I believe document.getElementById("foo").onselectstart = function(){return false} won't help here. – Zara May 22 '13 at 08:00
  • This is only way for disable select text in internet explorer 7, I tested it in a TWebBrowser in delphi and it works! – Evilripper Jun 01 '16 at 14:05
0

For IE11 I used

-ms-user-select: none;

And it did the trick

pavlovic265
  • 491
  • 2
  • 8