I want a custom context menu and so need to be able to disable the context menu when the right mouse button is clicked.
I think that previously I did this by ‘preventDefault’ and ‘stopPropagation’ on the onContextMenu event. But that doesn’t work.
I first tried attaching the event listener to the body element and then to the document and finally the window.
When the right mouse is clicked the alert is shown and when the alert is dismissed the chrome browser context menu appears.
The ‘if(!ev.ctrlKey)’ is so I can have the browser context menu by using the control right click.
My next thought was to add a mouse down event listener
Now both alerts are shown followed by the context menu.
A left button click brings up the relevant alert and the normal action does not occur so the mouse down ev.preventDefault is working.
preventDefault and stopPropagation are functions, and need to be called as such.
I’ve seen this applied which seems to work (in mac chrome):
document.addEventListener('contextmenu', event => event.preventDefault());
However are you sure this is a good idea?
I immediately leave sites that disable my right click.
Yup, me too, unless there’s very good reason (e.g. Google Docs).
In fact I hate sites that mess with any native browser functionality. E.g. Discourse overrides Ctrl+F to make you use its search functionality, which is almost never what I want to do.
AFAIK, doing ctrl-f twice escapes the hijack and cedes to the browser.
It does indeed.
Took me a while to work that out
You are so correct. It is always these stupid things which trip you up.
Just for the record, this is an app which will be run on my desktop and laptop only.
I do not envision making it publicly available.
It has to be run on Chrome as Chrome has modal dialogs which are essential for it.
Do you mean support for the
Yes it sports the dialog element.
Not only that but also modal dialogs.
And you can even cake another modal dialog from a modal dialog which returns back to the previous dialog when the new one is dismissed.
It is truely amazing.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.