禁止選擇文本和禁用右鍵 v1.0


var zhonghao={
//綁定事件
myAddEvent: function(obj, sEvent, fn){if(obj.attachEvent){obj.attachEvent('on'+sEvent, fn);}else{obj.addEventListener(sEvent, fn, false);}},
//禁止選擇文本
disableselect:function(e){
var omitformtags=["input", "textarea", "select"]
omitformtags
=omitformtags.join("|")
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
},
reEnable:
function(){
return true
},

//禁用右鍵

stop:
function(){
return false;

}

}

zhonghao.myAddEvent(window,
"load",function(){

//禁止選擇文本

if (typeof document.onselectstart!="undefined")
document.onselectstart
=new Function ("return false");
else{
document.onmousedown
=zhonghao.disableselect ;
document.onmouseup
=zhonghao.reEnable ;
}


//禁止右鍵

document.oncontextmenu
=zhonghao.stop;
})

 

<script> function stop() {
return false };
document.oncontextmenu
= stop;
javascript: ;
</script>

 

function disableselect(e) {
var omitformtags = ["input", "textarea", "select"];
omitformtags
= omitformtags.join("|");
if (omitformtags.indexOf(e.target.tagName.toLowerCase()) == -1);
return false
};

function reEnable() {
return true
};
if (typeof document.onselectstart != "undefined") document.onselectstart = new Function("return false");
else {
document.onmousedown
= disableselect();
document.onmouseup
= reEnable()
}

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com