Javascript 屏蔽右键菜单效果代码
2015-02-06来源:易贤网

 最简单的所有都屏蔽右键菜单

代码如下:

<script type="text/javascript">

document.body.oncontextmenu=new function(){return false;};

</script>

我们希望在INPUT、text、TEXTAREA中可以实现右击,但在其它页面都要屏蔽右键菜单

实例代码

代码如下:

<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>

更多信息请查看IT技术专栏

2026公务员·事业单位培训课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息