How to disable Text Selection on your website

How to disable Text Selection on your website (Script)

Disabling text selection is a simple way to get internet users and competitors to avoid copying your web content. Once text selection is disabled, your website visitors will no longer be able to select characters on your website with their mouse.

Disabling text selection is a simple way to get internet users and competitors to avoid copying your web content. Once text selection is disabled, your website visitors will no longer be able to select characters on your website with their mouse.

disable text selection script
Image: Text Selection

If you wish to disable website visitors from selecting text on your website follow the simple steps below.

1. First copy and paste the script below before the </head> tag of your webpage or at the bottom of your header.php template file on WordPress.

<script type="text/javascript">

/***********************************************
* Disable Text Selection
***********************************************/

function disableSelection(target) {
if (typeof target.onselectstart!="undefined")
 target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined")
 target.style.MozUserSelect="none"
else
 target.onmousedown=function(){return false}
target.style.cursor = "default"
}

</script>

2. Next, copy and paste the script below before the </body> tag on the webpage you wish to disable text selection on. If you are using WordPress you can add this snippet to your header.php file in order to disable text selection on all webpages of your website. You can even add the script below to individual pages, posts, and template files like category.php to simply remove text selection from single webpages.

<script type="text/javascript">
disableSelection(document.body)
</script>

Sean Doyle

Sean is a tech author and security researcher with more than 20 years of experience in cybersecurity, privacy, malware analysis, analytics, and online marketing. He focuses on clear reporting, deep technical investigation, and practical guidance that helps readers stay safe in a fast-moving digital landscape. His work continues to appear in respected publications, including articles written for Private Internet Access. Through Botcrawl and his ongoing cybersecurity coverage, Sean provides trusted insights on data breaches, malware threats, and online safety for individuals and businesses worldwide.

More Reading

Post navigation

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.