Any way to prevent “deselection” of highlighted text?

前端 未结 6 889
南旧
南旧 2020-12-10 13:54

Highlight some text on this webpage, then click basically anywhere on the document. Your selection will disappear.

Is there a way to prevent this behavior when the

6条回答
  •  抹茶落季
    2020-12-10 14:37

    This works for me on Firefox, haven't tried IE though. Try clicking on the foo.style.preventDeselect = "true"; line when you have text selected. Uses the mousedown event.

    
    
    
      
    
    
    
    
    Highlight some text on this webpage, then click basically anywhere on the document. Your selection will disappear.

    Is there a way to prevent this behavior when the user clicks on a specific element, either by CSS or Javascript?

    E.g.:

    var element = document.getElementById("foo");
    foo.onclick = function(e){
    //some magic here that prevents deselection from occuring
    }

    or

    foo.style.preventDeselect = "true";

    Thanks!

提交回复
热议问题