Javascript 屏蔽右鍵菜單效果代碼

字號(hào):


    最簡(jiǎn)單的所有都屏蔽右鍵菜單
    代碼如下:
    <script type="text/javascript">
    document.body.oncontextmenu=new function(){return false;};
    </script>
    我們希望在INPUT、text、TEXTAREA中可以實(shí)現(xiàn)右擊,但在其它頁(yè)面都要屏蔽右鍵菜單
    實(shí)例代碼
    代碼如下:
    <script type="text/javascript">
    //屏蔽右鍵菜單
    document.oncontextmenu = function (event){
    if(window.event){
    event = window.event;
    }try{
    var the = event.srcElement;
    if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
    return false;
    }
    return true;
    }catch (e){
    return false;
    }
    }
    </script>