JSI Tip 9487. How do I prevent the right-click context menu from appearing on a Web page that I authored, using Internet Explorer 5.0 or later?

RSS
Subscribe to Windows IT Pro | See More Internet Explorer (IE) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!
 
 
Click here to find out more!

 

 

9487 » How do I prevent the right-click context menu from appearing on a Web page that I authored, using Internet Explorer 5.0 or later? 23-Jun-05

 

 

settings

  ContextMenu takes an optional settings object that lets you style your menu and bind click handlers to each option. ContextMenu supports the following properties in the settings object:

 

bindings
An object containing "id":function pairs. The supplied function is the action to be performed when the associated item is clicked. The element that triggered the current menu is passed to this handler as the first parameter. 
Note: This behaviour has changed from r1 where you needed a "#" before the id
menuStyle
An object containing styleName:value pairs for styling the containing <ul> menu.
itemStyle
An object containing styleName:value pairs for styling the <li> elements.
itemHoverStyle
An object containing styleName:value pairs for styling the hover behaviour of <li> elements.
shadow
Boolean: display a basic drop shadow on the menu. 
Defaults to true
eventPosX
Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientX". 
Defaults to: 'pageX'
eventPosY
Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientY". 
Defaults to: 'pageY'
onContextMenu(event)
A custom event function which runs before the context menu is displayed. If the function returns false the menu is not displayed. This allows you to attach the context menu to a large block element (or the entire document) and then filter on right click whether or not the context menu should be shown.
onShowMenu(eventmenu)
A custom event function which runs before the menu is displayed. It is passed a reference to the menu element and allows you to manipulate the output before the menu is shown. This allows you to hide/show options or anything else you can think of before showing the context menu to the user. This function must return the menu.

 

 

settings

 

ContextMenu takes an optional settings object that lets you style your menu and bind click handlers to each option. ContextMenu supports the following properties in the settings object:

bindings
An object containing "id":function pairs. The supplied function is the action to be performed when the associated item is clicked. The element that triggered the current menu is passed to this handler as the first parameter. 
Note: This behaviour has changed from r1 where you needed a "#" before the id
menuStyle
An object containing styleName:value pairs for styling the containing <ul> menu.
itemStyle
An object containing styleName:value pairs for styling the <li> elements.
itemHoverStyle
An object containing styleName:value pairs for styling the hover behaviour of <li> elements.
shadow
Boolean: display a basic drop shadow on the menu. 
Defaults to true
eventPosX
Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientX". 
Defaults to: 'pageX'
eventPosY
Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientY". 
Defaults to: 'pageY'
onContextMenu(event)
A custom event function which runs before the context menu is displayed. If the function returns false the menu is not displayed. This allows you to attach the context menu to a large block element (or the entire document) and then filter on right click whether or not the context menu should be shown.
onShowMenu(eventmenu)

A custom event function which runs before the menu is displayed. It is passed a reference to the menu element and allows you to manipulate the output before the menu is shown. This allows you to hide/show options or anything else you can think of before showing the context menu to the user. This function must return the menu.