Question

In IE 10, when you click on any text while holding the CTRL key the browser selects the text (which means the text gains focus and I want to avoid this because I have some multi-select scenario where CTRL+click means add/remove-select).

How can I disable this "feature"?

BTW, I still want to be able to select the text using the usual mouse actions.

Was it helpful?

Solution

This feature can be disabled by disabling selection completely.

This can be done by using -ms-user-select which has been introduced in IE10. (see also: http://ie.microsoft.com/testdrive/HTML5/msUserSelect/Default.html)

Example: To disable selection add the following css class to the element containing the text or one of its parents:

.notselectable
{
    -ms-user-select: none;
}

OTHER TIPS

To prevent IE 8 CTRL and SHIFT click text selection on individual element, use this:

var obj = document.createElement("DIV");
obj.onselectstart = function(){
  return false;
}

To prevent text selection on document, use this:

window.onload = function(){
  document.onselectstart = function(){
    return false;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top