Wednesday 22 October 2014

How to prevent your webpage content being copied ?

No Copy and Paste Script

Did you know that you can disable the copy and paste function on your web pages? Of course you did, that's why you're here, to see how it's done. Call me a cwazy wabbit for asking.

This little JavaScript snippet will prevent someone from highlighting your text and using the copy function to copy it and rip it off. It also prevents them from using Ctrl + A to select all the text, or using the right-click menu to Select All. Go ahead, try to copy the text on this page . . . I'll wait.

Of course, since it is JavaScript, it doesn't work if the visitor has JavaScript disabled or has a browser that doesn't support JavaScript. That isn't very many users, but anyone with some experience would know a way around this trick. It will stop most new users though, and at least make it harder for everyone else. That may be all the discouragement they need to move on to easier pickings.

Just add the following code to the HEAD tag of your web page:
 
 <pre>
&lt;script type="text/JavaScript"&gt;
//courtesy of BoogieJack.com
function killCopy(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=killCopy
document.onclick=reEnable
}
&lt;/script&gt;
</pre>

Good thing that's a short bit of code to type isn't it, since you can't copy and paste from this page where the code is being demonstrated? Just kidding&mdash;if you view the source code you can copy and paste it from there.

No comments:

Post a Comment