方法一:利用鼠标button的键值

<script language="javascript">
            function blockright(oEvent) {
                var oDiv = document.getElementById("display");
                if (window.event) oEvent = window.event; //处理兼容性,获得事件对象
                if (oEvent.button == 2)
                    alert("不能使用");
            }
            window.onload = function() {
                document.onmousedown = blockright;
            }
        </script>
        <div>
            <textarea rows="4" cols="50" id="textin">
            </textarea>
            <p id="display"></p>
        </div>

方法二:鼠标的contextmenu

(这里需要ie的return属性和DOM d prevevrDefault()方法)

<script language="javascript">
            function blockright(oEvent) {
                if (window.event) {
                    oEvent = window.event; //处理兼容性,获得事件对象
                    oEvent.returnValue = false;
                }else
                oEvent.preventDefault();
            }
            window.onload = function() {
                document.oncontextmenu = blockright;
            }
        </script>

contextmenu事件在自定义右键内容时常常使用,即屏蔽右键内容=后自定义一个div显示菜单。

相关文章:

  • 2021-09-10
  • 2021-09-10
  • 2021-11-24
  • 2021-10-22
  • 2021-12-15
  • 2021-09-10
  • 2021-11-18
  • 2021-12-30
猜你喜欢
  • 2021-09-10
  • 2021-09-10
  • 2021-09-10
  • 2021-08-29
  • 2021-09-10
  • 2021-10-18
  • 2021-11-04
相关资源
相似解决方案