I know that you can add context menu items(currently only in Firefox) but can you replace the context menu entirely with items specified?
By that I mean that if I create a context menu with:
Then when opening the context menu ONLY those items would appear.
I also mean according to the HTML5 menu element specification and not current implementations.
No, HTML5 doesn't and you can't. An important reason for having the menu element affect the context menu was to allow authors to be able to put operations on the context menu without disrupting all the facilities that are built into the browser and are important to the user. So allowing the web page author to remove the existing context menu options would defeat the point.
It isn't HTML that supports this, but the browser.
Some browsers do indeed allow you to disable the context menu and activate something else on right click, but others don't.
It's been possible in most browsers for ages (certainly long before HTML5), but one or two browsers have never allowed it, on the grounds that you're interfering with the standard browser UI. (Opera was always the odd one out here)
For browsers that do support it, you need to use the onmousedown event, which will give you an event object that will tell you which mouse button was pressed.
Or you can use a jQuery plugin -- there seem to be a few of them around for this. Try this one or this one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With