July 6, 2015

How to Disable Text Selection on Web Page using JavaScript

This JavaScript will Disable select, copy and paste of the content. Put below given JavaScript in <script></script> tag inside <head></head>  tag of your webpage.

If you want to use this script on your blog then go-to Layout > Add a Gadget > Use HTML/JavaScript Gadget and Paste below given code inside it.

JavaScript Code:
 
//Script open tag 
 //form tags to omit in NS6+:  
 var omitformtags=["input", "textarea", "select"]  
 omitformtags=omitformtags.join("|")  
 function disableselect(e){  
 if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)  
 return false  
 }  
 function reEnable(){  
 return true  
 }  
 if (typeof document.onselectstart!="undefined")  
 document.onselectstart=new Function ("return false")  
 else{  
 document.onmousedown=disableselect  
 document.onmouseup=reEnable  
 }  
 //Script close tag  

0 comments:

Disclaimer

We shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its response or damage to your system. We do not guarantee that the integrity or security of this communication has been maintained or that this communication is free of viruses, interceptions or interferences. Anyone communicating with us by email accepts the risks involved and their consequences. We accept no liability for any damage caused by any virus transmitted by this site.