Skip to content

Instantly share code, notes, and snippets.

@jookyboi
Created March 21, 2011 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jookyboi/880434 to your computer and use it in GitHub Desktop.
Save jookyboi/880434 to your computer and use it in GitHub Desktop.
Disable click-and-drag selection in all browsers through css and javascript
for IE:
function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
target.style.MozUserSelect="none"
else //All other route (ie: Opera)
target.onmousedown=function(){return false}
target.style.cursor = "default"
}
for others:
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment