簡體   English   中英

在Javascript中禁用滾動按鈕單擊

[英]Disable Scroll button click in Javascript

請幫助我糾正以下代碼段,右鍵單擊禁用可以正常工作,但是中鍵(滾動按鈕)禁用不起作用。它顯示消息,但是單擊[確定]到警告框。 它將在新選項卡中打開。我正在使用Firefox瀏覽器謝謝

 function clickIE() { if (document.all) { alert("Right click is disabled2"); return false; } } function clickNS(e) { if(document.layers||(document.getElementById&&!document.all)) { if (e.which==3) { alert("Right click is disabled1"); e.preventDefault(); return false; } if(e.which==2) { alert("Right click is disabled3"); e.preventDefault(); return false; } } } if (document.layers) { document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS; } else { document.onmouseup=clickNS;document.oncontextmenu=clickIE; } document.oncontextmenu=new Function("return false") 
 <a href="#">Hello world</a> 

我將e.preventDefault()移到方法的頂部:

function clickNS(e) 
{  
    e.preventDefault();

    if(document.layers||(document.getElementById&&!document.all)) 
    {
        if (e.which==3)
        {
            alert("Right click is disabled1");

            return false;
        }
        if(e.which==2)
        {
            alert("Right click is disabled3");
            return false;
        }
    }
}

因為如果不滿足第一個條件會發生什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM