Disable Select and Print

Select

You can discourage people from selecting and copying your page content by disabling their ability to select your page content directly. To do this you need to include the following Javascript in the head section of your page.

// disable select
document.onselectstart=new Function('return false');
function ds(e){return false;}
function ra(){return true;}
document.onmousedown=ds;
document.onclick=ra;

As an example of how this javascript works, I have included a copy in the head section of this page so you probably can't select the code above to copy it for your site. You can download it instead.

Note that this script works with IE 5+, Netscape 6+ and Opera 8+ only. It doesn't work at all with earlier browsers and it doesn't stop people grabbing the text from your page source.

Print

Disabling print is easier and can be done with a single stylesheet statement, no Javascript required. The following will stop the content of your page being able to be printed in all version 5+ browsers.

/* disable print */
@media print {body {display:none;}}

You should not have any problem retyping that line into the end of your stylesheet if your browser stops you being able to select it from this page.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate