How to insert disable text selection script in your website? (

We all genuine content writers have a common issue of content theft (plagiarism) by scammers. To control or avoid this issue i have came up with HTML Java script to disable text selection option for any visitor of your website.

Add this script to the HEAD section of your page:
<script type="text/javascript">
function disableSelection(target)
if (typeof target.onselectstart!="undefined")                       =>>IE route
                        target.onselectstart=function(){return false}
else if (typeof!="undefined")    =>>Firefox route
else                                                                                            =>>All other route (ie: Opera)
                        target.onmousedown=function(){return false} = "default"
=>>Sample usages
//disableSelection(document.body) //Disable text selection on entire body
//disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv"

With the script installed, just call the function disableSelection(target) at the very end of the document with a reference to the element you wish to disable text within. A few examples:

<script type="text/javascript">
disableSelection(document.body)   (=>> For disabling text selection on entire body of page) don't use this text

<script type="text/javascript">
var somediv=document.getElementById("mydiv")
disableSelection(somediv)              (=>> For disabling text selection within DIV with id="mydiv")

<script type="text/javascript">
var alltables=document.getElementsByTagName("table")
for (var i=0; i<alltables.length; i++)
disableSelection(alltables[i])           (=>> For disabling text selection within all tables on the page)

User Note:

Make sure to call the above functions at the end of the document to ensure the element to disable text is defined before the function is called. Comment us below with your technique for disabling copy text option.

No comments:

Post a Comment