home >
Right click menus
Right Clickable Menu Item
Select a link or any element that can handle a onmousedown event. NOTE: onclick is only for left mouse button.
Like so: <a href="#" onmousedown="showMenu(event);">Right Clickable Menu Item</a>
Here's some sample javascript to build the menu object
/**
* start the menu, if right button is clicked then create a div and then call the menu
* drawing function with the newly created div's id
* @param object event
*/
function showMenu (oEvent)
{
if (oEvent.button != 2)
{
alert('try right clicking');
return;
}
else
{
var oDiv = createDiv('menu', oEvent);
drawMenu('menu');
}
}
/**
* Draw the menu
* @param string div name to house the menu
*/
function drawMenu (sDiv)
{
var oMenu = new Menu(sDiv);
oMenu.addItem('menu item 1', 'alert(\'fire menu 1\'); removeDiv(\'' + sDiv + '\');');
oMenu.addItem('menu item 2', 'alert(\'fire menu 2\'); removeDiv(\'' + sDiv + '\');');
oMenu.addItem('menu item 3', 'alert(\'fire menu 3\'); removeDiv(\'' + sDiv + '\');');
oMenu.addItem('properties', 'alert(\'here are the properties\'); removeDiv(\'' + sDiv + '\');');
oMenu.drawMenu();
}