OnContextMenu Event



IE5 allows developers to easily determine when somebody right-clicks on an element. It is also very easy to override the standard behavior for that event.
Try right-clicking the different divs for several examples.

1. Builtin context menu will always show when you right-click in this box.
Code:
//no code necessary

2. Context menu will only show if you ctrl-right-click in this box. Useful for developing/debugging.
Code: oncontextmenu="return event.ctrlKey"

3. Context menu will never show when you right-click in this box.
Code:
oncontextmenu="return false"

4. Custom menu will show when you right-click in this box.
Code:
oncontextmenu="showMenu();return false;"

5. Custom menu will show when you right-click in this box. If you ctrl-right-click, you will see the standard menu.
Code:
oncontextmenu="if (!event.ctrlKey){showMenu();return false;} else {menu1.style.display='none'}"


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