How to disable selection of text on a web page

后端 未结 6 1146
死守一世寂寞
死守一世寂寞 2020-12-08 06:52

I am trying to make webpage very native. How to remove select,select all property in webpage?

相关标签:
6条回答
  • 2020-12-08 07:08

    This JavaScript will Disable select, copy and paste of the content But if user will save page to local machine they will be able to do "anything" they want with your code.

    //disable cut copy past
    var message = "";
    function clickIE() { if (document.all) { (message); return false; } }
    function clickNS(e) {
        if(document.layers || (document.getElementById && !document.all)) {
            if (e.which == 2 || e.which == 3) { (message); return false; }
        }
    }
    if (document.layers)
    { document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS; }
    else { document.onmouseup = clickNS; document.oncontextmenu = clickIE; }
     document.oncontextmenu = new Function("return false")
    
    
    //for disable select option
    document.onselectstart = new Function('return false');
    function dMDown(e) { return false; }
    function dOClick() { return true; }
    document.onmousedown = dMDown;
    document.onclick = dOClick;
    
    0 讨论(0)
  • 2020-12-08 07:10

    Disable selection of every element with CSS

    body {
      -webkit-user-select: none;
         -moz-user-select: -moz-none;
          -ms-user-select: none;
              user-select: none;
    }
    

    This is supported by Chrome, Safari, Firefox, IE 10, and iOS Devices. More info on MDN page.

    Edit: If you want <input> and <textarea> to remain selectable in Firefox, add:

    input,
    textarea {
         -moz-user-select: text;
    }
    

    Disable context menu with jQuery

    $(document).on("contextmenu", function (event) { event.preventDefault(); });
    
    0 讨论(0)
  • 2020-12-08 07:10

    You Can disable by adding attribute in your body tag oncontextmenu="return false;

    <body oncontextmenu="return false;">
    
    0 讨论(0)
  • 2020-12-08 07:12
    element_name{
      -webkit-touch-callout: none; 
      -webkit-user-select: none;
      -khtml-user-select: none; 
      -moz-user-select: none;
      -ms-user-select: none; 
       user-select: none;
     }
    
    0 讨论(0)
  • 2020-12-08 07:16

    use this code https://www.docsity.com/it/teorie-e-pratiche-del-web-4/556038/

    body, html{     
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;  
    }
    
    0 讨论(0)
  • 2020-12-08 07:25

    may this help you

    <div onselectstart="return false;" style="-moz-user-select: none;">
    
    0 讨论(0)
提交回复
热议问题