码迷,mamicode.com
首页 > 其他好文 > 详细

页面禁止右击

时间:2016-05-25 20:45:21      阅读:129      评论:0      收藏: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;

 

 

})

页面禁止右击

标签:

原文地址:http://www.cnblogs.com/zuosong160522/p/5528172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!