Skip to content Skip to sidebar Skip to footer

Disable Select, Copy And Paste Of The Content Of HTML Pages In Mozilla Firefox

I want to disable select, copy and paste of the content of HTML pages in Mozilla Firefox. I have used jQuery and JavaScript to disable right-click and copy, select, paste of the co

Solution 1:

Just copy and Paste the below javascript in your webpage:

<script language="javascript" type="text/javascript"> 
      function disableselect(e) {             
          return false 
      } 
      function reEnable() { 
          return true 
      } 

      document.onselectstart = new Function("return false") 

      if (window.sidebar) { 
          document.onmousedown = disableselect                    // for mozilla           
          document.onclick = reEnable 
      } 

      function clickIE() { 
          if (document.all) { 
              (message); 
              return false; 
          } 
      } 


      document.oncontextmenu = new Function("return false") 

      var element = document.getElementById('tbl'); 

      element.onmousedown = function () { return false; }        // For Mozilla Browser

   </script>

Note:If the above code not works for Firefox then add style="-moz-user-select:none" in the body tag which needs to be restricted alongwith the above code.


Solution 2:

Try this first work for block select and second allow to select in textarea and input field.

html,body{
        -webkit-user-select: none;
        -moz-user-select: -moz-none;
        -ms-user-select: none;
        user-select: none;
        -khtml-user-select: none;
    }
    input, textarea{
        -webkit-user-select:  text !important;
        -moz-user-select:  text !important;
        -ms-user-select: text !important;
        user-select: text !important;
        -khtml-user-select: text !important;
    }

Solution 3:

A) Apply this code in your html document inside the body tag

ondragstart=’return false’ onselectstart=’return false’ – to disable copy and paste

B) Use this script in your html document before closing the closing the head tag

<script language=JavaScript>
    var message=”Function Disabled! OR whatever text you want to show on right click”;         
    function clickIE4(){
        if (event.button==2){ alert(message); return false; }
    }
    function clickNS4(e){
        if (document.layers||document.getElementById&&!document.all){ 
            if (e.which==2||e.which==3){ 
                alert(message);
                return false; 
            } 
        }
    }
    if (document.layers){ 
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown=clickNS4;
    } else if (document.all&&!document.getElementById){
        document.onmousedown=clickIE4; 
    } 
    document.oncontextmenu=new Function(“alert(message); return false”) 
</script>

C) Give security to the contents by using the css elements in body tag

EX: in css file

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

This is BASIC protection! Advanced users will bypass it with ease by disabling JavaScript on their browser or using firebug.


Post a Comment for "Disable Select, Copy And Paste Of The Content Of HTML Pages In Mozilla Firefox"