October 27, 2011

How can we disable right click on Web Page

If you want to disable right click on a web page you can use below script to do it.

function clickIE4(){
            if (event.button==2){
            return false;
            }
        }
        function clickNS4(e){
            if (document.layers||document.getElementById&&!document.all){
            if (e.which==2||e.which==3){
            return false;
            }
            }
        }
        if (document.layers){
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown=clickNS4;
        }
        else if (document.all&&!document.getElementById){
        document.onmousedown=clickIE4;
        }
        function rightClick(str)
        {
       
            if (str=="F")
        {
                document.oncontextmenu=new Function("return false");
                if(window.event && window.event.keyCode == 8)        
                {
                    window.event.keyCode = 0;       
                }
        }
            else
        {
                document.oncontextmenu=new Function("return true");
                if(window.event && window.event.keyCode == 8)        
                {
                    return true;       
                }
        }
        }


That’s It.
Enjoy Learning.

No comments:

Post a Comment