logo竹子建站
禁止复制网站内容代码
2019-12-02 16:42:06

鼠标左右键都可以触发click,mousedown等事件,可以通过event.which使得鼠标右键不出发事件,但是鼠标右键自带的下面的选项是可以被触发的,所以需要把下面默认的选项框也隐藏掉

event.which 属性返回指定事件上哪个键盘键或鼠标按钮被按下;

这样之后,点击右键,不会触发事件,自带的事件选框也没有了~

 

 

 

<script type="text/javascript">
    function iEsc() { return false; }
    function iRec() { return true; }
    function DisableKeys() {
        if (event.ctrlKey || event.shiftKey || event.altKey) {
            window.event.returnValue = false;
            iEsc();
        }
    }
    function DisableRightClick(www_qsyz_net) {
        if (window.Event) {
            if (www_qsyz_net.which == 2 || www_qsyz_net.which == 3)
                iEsc();
            }
        else if (event.button == 2 || event.button == 3) {
            event.cancelBubble = true
         event.returnValue = false;
            iEsc();
        }
    }
    document.ondragstart = iEsc;
    document.onkeydown = DisableKeys;
    document.oncontextmenu = iEsc;
    if (typeof document.onselectstart != "undefined")
        document.onselectstart = iEsc;
    else {
        document.onmousedown = iEsc;
        document.onmouseup = iRec;
    }
</script>
<style type="text/css">
body {
    -moz-user-select: none;
    -webkit-user-select: none;
}
</style>

相关推荐