×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
2
Language: Javascript
Posted by: petecocoon
Added: May 17, 2012 9:27 AM
Views: 108
This snippet disable mouse text selection on a html page
  1. disableSelection = function(target){
  2.         if (typeof target.onselectstart!="undefined"){         
  3.                 //IE route
  4.                 target.onselectstart = function(){ return false; };
  5.         }else if(typeof target.style.MozUserSelect!="undefined"){
  6.                 //Firefox route
  7.                 target.style.MozUserSelect = "none";
  8.         }else{
  9.                 //All other route (ie: Opera)
  10.                 target.onmousedown = function(){ return false; };
  11.         }
  12.         target.style.cursor = "default";
  13. }