[removed] Disable text selection via doubleclick

前端 未结 5 966
走了就别回头了
走了就别回头了 2020-12-03 02:49

When double-clicking on a html page most browsers select the word you double-click on (or the paragraph you triple-click on). Is there a way to get rid of this behavior?

5条回答
  •  北海茫月
    2020-12-03 03:17

    Just to throw this out there, but here's the code I slap into my pages where I expect users to be clicking rapidly. However, this will also disable standard click-n-drag text selection.

    document.body.onselectstart = function() {
        return false;
    }
    document.body.style.MozUserSelect = "none";
    if (navigator.userAgent.toLowerCase().indexOf("opera") != -1) {
        document.body.onmousedown = function() {
            return false;
        }
    }
    

    Seems to work well for me.

提交回复
热议问题