Pixel-perfect OS-style javascript context menu
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
about
contextmenu.css
contextmenu.js
index.html
license.md
package.json
readme.md
repeat-x.png
repeat-y.png
test.html

readme.md

Contextmenu is a javascript library (with no dependencies) that allows the creation of native-looking right-click menus within a web page.

Don't use this in an attempt to replace the default context menu (e.g., to prevent Download Linked File As..., Save Image As..) because that is very annoying. The intended use is really for javascript-heavy web apps.

Screenshots

Mac OS X Lion Style

Windows Vista Style

Windows 7 Style

Ubuntu Style

Fallback Style

Usage

Requirements:

  • contextmenu.js
  • contextmenu.css

Either specify the markup using HTML context-menu notation HTML Spec, or use the simple Javascript API provided by the contextmenu object which builds DOM nodes, and adds some javascript to ensure browser compatibility.

API Example

var menu = contextmenu([
	{
		label: "First Item",
		onclick: function (e){
			document.body.style.background = "green";
		}
	},
	{
		label: "Sub menu",
		children: [
			{
				label: "Another Item"
			}
		]
	}
]);

// Hook up an event to launch it
contextmenu.attach(domNode, menu);

//Or Show menu directly
contextmenu.show(menu, 300, 200);

Sites using Contextmenu