开发者

Text unselectable in IE

I require one HTML element (Label) on my page to be unselectable for IE ... currently I have tried

  1. Unselectable=on
  2. onselectreturn=false;

none of which is helping me out.

For Firefox and Chrome i have set the following CSS property which are working absolutely fine ... but the problem as always with the IE.

CSS properties you have set:

-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;

is there any alternative or IE-hack?

An开发者_JAVA技巧 answer on Stack Overflow has helped me out but not for IE.


<label unselectable="on"> should work for IE in the HTML. If applying it from javascript you MUST use setAttribute: labelEl.setAttribute("unselectable","on"). labelEl.unselectable = "on" does not work (tested in IE9).

Note that the "unselectable" attribute only affects text directly inside the element, not within its children - you need to set unselectable on them also, if that's the effect you want.


In IE8 there are two ways to make an element unselectable:

1.) myElement.unselectable = "on"; // Does not work on body elements

2.) myElement.onselectstart = function (){ return false; }

Once an element is unselectable, users cannot select from within that element. However, they are still able to select either the text or the box of the element by dragging into it from within another element which is not unselectable.

I have tried to work around this by cancelling various events on myElement (ondragenter, oncontrolselect, onmouseenter, onselectionchange...), it didn't work.

All this applies only to IE8


Set unselectable to off and it should work.

<label unselectable="off">Something</label>

http://jsfiddle.net/sWguE/1/

This also works for me

<label onselect="return false">Something</label> 

http://jsfiddle.net/sWguE/3/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜