Jump to Real's How-to Main page

Disable text selection in a page

This javascript disables the ability to select text with mouse. You can try it on this page (works on IE and FF).
<SCRIPT type="text/javascript">
if (typeof document.onselectstart!="undefined") {
  document.onselectstart=new Function ("return false");
}
else{
  document.onmousedown=new Function ("return false");
  document.onmouseup=new Function ("return true");
}
</SCRIPT>
However, it's not a good "protection" because you can return to the normal behaviour with a simple javascript url :

IE here to put back the mouse selection
FF here to put back the mouse selection


If you find this article useful, consider making a small donation
to show your supportfor this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2007
[ home ]