Sometimes, we do not want people to copy the text on some of our web pages, here is a script which prevents user (not advanced users) from selecting the text.
For better results put the JavaScript code inline and not in a separate JS file.
For better results put the JavaScript code inline and not in a separate JS file.
Code: JavaScript
// specify allowed tags for some browsers
var allowedTags=["input", "textarea", "select"]
allowedTags=allowedTags.join("|");
function disableselect(e)
{
if (allowedTags.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;
}