I recently came across a website that disabled text selection, preventing anyone from easily copying and pasting text. I have a bookmarklet that disables similar attempts to block context menus using JavaScript, and I'm wondering if it would be possible to do something similar for text selection.
function disableSelection(target){
if (typeof target.onselectstart!="undefined") //For IE
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //For Firefox
target.style.MozUserSelect="none"
else //All other route (For Opera)
target.onmousedown=function(){return false}
target.style.cursor = "default"
}
Elsewhere the function is called with disableSelection(document.body)
.
The solution from my context menu bookmarklet is also probably necessary:
javascript:void(document.onmousedown=null);
void(document.onclick=null);
void(document.oncontextmenu=null)
Finally, I had seen elsewhere on StackOverflow that CSS could also be used:
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
Is there a method to fight all of these at once and end this tyranny over my browser? How would I both enable MozUserSelect
/SelectStart
for all elements and set the CSS properties?