Disabling the Context Menu - DHTML Lab - DHTML Diner | 4
Disabling the Context Menu
Explorer for Windows
Explorer for Windows assigns context menus to Operating System object or component, not events within a browser. This is an oversimplification, of course, but should give you an idea why we cannot control the menu through event handling.
Explorer 4
In Explorer 4, there is no way to disable the context menu unless you turn your page into an Operating System object (COM object). The only way to do this is by defining your page as a DHTML Scriptlet, and loading it into another page using the OBJECT tag.
Scriptlet technology was introduced in Explorer 4, and after the initial hoopla, was ignored by further IE developments. Personally, I think Scriptlets are great, but for platform and browser-specific applications only.
And because they are OBJECTs, they can be viewed as hostile Active-X controls, even though they are innocent HTML pages, by high IE security settings.
To demonstrate the context menu behavior, the previous page of this article is inserted twice below. The first time into an IFRAME, the second as a Scriptlet using OBJECT.
These examples will only appear in Explorer. If you have a high security setting the second example may not appear:
<IFRAME WIDTH=250 HEIGHT=300
SRC="3.html"></IFRAME> |
<OBJECT TYPE="text/x-scriptlet" DATA="3.html"
WIDTH=250 HEIGHT=300></OBJECT>
|
Explorer 5
Explorer 5 righted this wrong with a special event handler specifically introduced for disabling the context menu, oncontextmenu. All elements can be assigned this handler. By returning false, from the handler, the menu is disabled. For example, this paragraph has no context menu for Explorer 5 Windows. The code used was:
<P oncontextmenu="return false"
Explorer 5 righted this wrong... The code used was:</P>
To disable the context menu in the complete document, we can use this statement:
document.oncontextmenu = function(){return false}
Now, let's put all the code snippets together.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.Created: April 28, 2000
Revised: April 28, 2000
URL: http://www.webreference.com/dhtml/diner/contextmenu/4.html

Find a programming school near you