Javascript屏蔽鼠标右键,其实作用也不大,也许是为了防止别人查看源代码,其实想查看源代码有多种途径,未必需要通过鼠标右键。不过当我们自定义鼠标右键弹出菜单时,也许需要这些。

下面是源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Javascript屏蔽鼠标右键-前端开发-BeyondWeb.cn</title>
    <script type="text/javascript">
        /*
        //for ie6,7,8,9,10 and webkit and opera
        document.oncontextmenu = function () {
            window.event.returnValue = false;
        }
        */
        //for ie6,7,8,9,10 and webkit and opera and firefox
        document.oncontextmenu=function(e){
            return false;
        }
  
    </script>
</head>
<body>
    <p>鼠标右键被屏蔽</p>
    <p>鼠标右键被屏蔽</p>
    <p>鼠标右键被屏蔽</p>
    <p>鼠标右键被屏蔽</p>
    <p>鼠标右键被屏蔽</p>
</body>
</html>