How to disable right click menu in IE, Netscape 4 and Netscape 6

Giganews Newsgroups
Subject: How to disable right click menu in IE, Netscape 4 and Netscape 6
Posted by:  yaktipp…@yahoo.com (yaktipper)
Date: 9 Jul 2003

This explains how to disable the view source / right-click menu in
Netscape 4, Netscape 6 and Internet Explorer (IE).

<script language="JavaScript">
//This code is the beginning of the right click disable
function right(e) {
    //This function is for Net 4.
    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which ==
2))
        {
        return false;
        }
    return true;
}

function context(){
    //This function takes care of Net 6 and IE.
    return false;
}

document.onmousedown=right;
document.oncontextmenu=context;
</script>

Note: If you set up a frame page, and in each frame include the above
code, the casual user will not be able to view the source.  If you use
frames, the browser menu option "View Source" will only view the main
frame page source, not the individual frame source.  However, any
sophisticated user will be able to still view all the source simply by
turning off javascript, or by using a browser that doesn't recognize
this script.

Note: Only tested on a Windows XP machine, run at your own risk.  You
may need to tweak the code for other platforms/browers, but you can
get the idea from this sample.

The reason I'm posting this is that it is very difficult for a novice
to find this information on the Net, as an immense amount of posts
declare this as impossible, and an equally immense amount of posts
scathingly denounce this as the worst thing you can do to a web page.
This post is for those people that simply want to meet a customer's
needs. Even if the request is a bad idea, customers still pay the
bills :)

Replies