oncontextmenu Event Sample

This sample shows how to use the oncontextmenu event handler, available in Microsoft® Internet Explorer 5 and later, to display both standard and custom context menus and prevent context menus from displaying. Experiment with each of the following boxes to see how you can apply different methods either to display or to inhibit context menus. Each box provides instructions for you to follow.

1. The default context menu always displays when you right-click in this box.
Code:
//no code necessary


2. The default context menu displays only if you right-click in this box while holding down the Ctrl key. This is useful for developing and debugging purposes.
Code:
oncontextmenu="return event.ctrlKey"


3. A context menu never displays when you right-click in this box.
Code:
oncontextmenu="return false"


4. A custom context menu displays when you right-click in this box.
Code:
oncontextmenu="showMenu();return false;"


5. A custom menu displays when you right-click in this box. If you right-click while holding down the Ctrl key, the default context menu displays.
Code:
oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}"




© 2000 Microsoft Corporation. All rights reserved. Terms of use.