How to make text in an html page unselectable for the visitors? I don’t know for what reasons you may need this, but here is the code you want, read below.
Source code for webtoolkit.unselectable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/**
*
* Unselectable text
* http://www.webtoolkit.info/
*
**/
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;
}
|