禁止使用鼠标左右键(跨浏览器实现)--鼠标事件

本文介绍了一段JavaScript代码,该代码可以实现在网页上禁用鼠标左右键的功能。通过对不同浏览器环境下鼠标事件的监听及判断,弹出警告框以阻止用户使用鼠标左右键。
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 2 <html>
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 5 <title>机制使用鼠标左右键</title>
 6 </head>
 7 <body>
 8 <script type="text/javascript">
 9 function click(){
10     if(navigator.appName=="Netscape" && event.button==0){
11         alert("禁止使用鼠标左键");
12     }
13     
14     if(navigator.appName=="Microsoft Internet Explorer" && event.button==1){
15         alert("禁止使用鼠标左键");
16     }
17     
18     if(navigator.appName=="Opera" && event.button==0){
19         alert("禁止使用鼠标左键");
20     }
21     
22     if(event.button==2){
23         alert("禁止使用鼠标右键");
24     }
25 }
26 document.onmousedown=click;
27 </script>
28 </body>
29 </html>

 

转载于:https://www.cnblogs.com/pinsige/p/3939626.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值