Make things inaccessible in IE

Here is my diagram I wrote in JS:

http://jsfiddle.net/49FVb/

css:

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

Works great for Chrome / FF, but in IE all items are still selectable, which looks weird when dragging and dropping bars.

How can I make this non-selectable in IE?

+7
source share
4 answers

In IE, you need the unselectable attribute in HTML:

 <div id="foo" unselectable="on">...</div> 

... or install it using JavaScript:

 document.getElementById("foo").setAttribute("unselectable", "on"); 

The thing you need to know about is that non-selectivity is not inherited by children of a non-selectable element. This means that you need to either put the attribute in the start tag of each element inside the <div> , or use JavaScript to do this recursively for the descendants of the element:

 function makeUnselectable(node) { if (node.nodeType == 1) { node.setAttribute("unselectable", "on"); } var child = node.firstChild; while (child) { makeUnselectable(child); child = child.nextSibling; } } makeUnselectable(document.getElementById("foo")); 
+14
source

You can use Javascript to make text inaccessible in all browsers:

 document.onselectstart=new Function('return false'); function noselect(e){return false;} function click(){return true;} document.onmousedown=noselect; document.onclick=click; 

This SO thread describes another way: Is there a way to make text unselected on an HTML page?

The cheapest way is <body onselectstart="return false">

A better way might be to use the following CSS:

 [unselectable=on] { -moz-user-select: none; -khtml-user-select: none; user-select: none; } 

and add IE unselectable property to the elements you want to make unselectable ( unselectable="on" in HTML; element.setAttribute("unselectable","on") in javascript)

Check out this nice little article on non-selectable text .

+5
source
+1
source

This seems to work well in Chrome and IE11 using jQuery ...

 function fMakeNodeUnselectable(node){ $(node).css({"cursor":"default","-moz-user-select":"-moz-none","-khtml-user-select":"none","-webkit-user-select":"none","-o-user-select":"none","user-select":"none"}); $(node).attr("unselectable","on"); } 
+1
source

All Articles