最近帮朋友修改他们的培训网站,需要屏蔽鼠标右键,还需要兼容IE,FF等浏览器,找了些方法,都只能支持IE的,但是火狐浏览器和谷歌都不行,今天请教了下高手,茅塞顿开啊,分享下代码吧:
-
<script type="text/javascript">
-
document.oncontextmenu = function (event){
-
if(window.event){
-
event = window.event;
-
}try{
-
var the = event.srcElement;
-
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
-
return false;
-
}
-
return true;
-
}catch (e){
-
return false;
-
}
-
}
-
</script>