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.

Était-ce utile?

La 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;
}

Autres conseils

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;
  }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top