Unselectable Text

There are many methods and options to make text unselectable on a website, but not all of them work on the major browsers. Below please find different source code to help you achieve this.

If you combine all the below source codes together in the same html/asp/aspx form, you’ll get all their functionality on the same page, thus no one can select any text from your website from the following browsers:

  • Internet Explorer 7
  • Firefox 3.0.4
  • Google Chrome 0.4.x
  • Opera 9.62

Source Code 1 – Unselectable

var Unselectable = {

enable : function(e) {
var e = e ? e : window.event;

if (e.button != 1) {
if (e.target) {
var targer = e.target;
} else if (e.srcElement) {
var targer = e.srcElement;
}

var targetTag = targer.tagName.toLowerCase();
if ((targetTag != “input”) && (targetTag != “textarea”)) {
return false;
}
}
},

disable : function () {
return true;
}

}

if (typeof(document.onselectstart) != “undefined”) {
document.onselectstart = Unselectable.enable;
} else {
document.onmousedown = Unselectable.enable;
document.onmouseup = Unselectable.disable;
}

You need to insert this in the <head> section of the html form in the following form: Continue reading