10

How does the MDN (Mozilla Developer Network) website change the context menu?
For example, this page.
I thought they created the whole context menu to call it when the contextmenu event is fired, but it seems a little crazy.
Furthermore, it doesn't work on Chrome, so I suppose it's a Firefox-only feature.
Does anybody know how they do it?
enter image description here

2 Answers2

10

Documentation is a bit sparse, but it's using the contextmenu attribute which is new in HTML5. It uses the menu HTML tag which is now different from its HTML4 implementation. Browser support isn't so great, but it is supported in Firefox 8.

Here is a screenshot of the DOM on the page showing the relevant HTML, the contextmenu attribute on the body and the menu tags which are expanded.

contextmenu dom

UPDATE: This answer previously stated that Chrome 36 and up supported this feature, as previously stated by the caniuse page. This appears not to be the case and caniuse has removed this information.

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
4

I just finished writing an article about HTML5 menus and browser support: https://dpogue.ca/articles/html5-menu.html

To summarize:

  • Firefox implements this using the older (not spec-compliant) type="context" attribute on the menu tag. There is a bug for Firefox to update to the newer spec.

  • Chrome implements it according to the spec (type="popup") as of Chrome 41, but it's behind the "Experimental Web Platform Features" flag.

Because of this difference in the type attribute, it's essentially impossible to target both implementations at the same time. While type="context" means that Firefox users will see the menu, it is contrary to the spec and probably won't be supported by other browsers.

dpogue
  • 553
  • 5
  • 7
  • For some reason it's not listed on the Chromium [Web Platform Status page](https://www.chromestatus.com/features#menu), but [here is the relevant bug](https://code.google.com/p/chromium/issues/detail?id=87553) for anyone who wants to track it. – janfoeh Mar 04 '15 at 18:24
  • Firefox bug: ["Update to spec"](https://bugzilla.mozilla.org/show_bug.cgi?id=897102) – janfoeh Mar 04 '15 at 20:59