1

I've found a lot of questions like this one, this one, and this one, purporting to show how to "simulate a right click" or "trigger the context menu", etc. Then I found this one, which simply says it can't be done. I think the first 3 questions are all triggering custom context menus, i.e. menus that are attached to replace the built-in one. I'd like to just simulate a user right-click on a particular element of my choice.

I've tried all the suggestions in the first questions -- varying combinations of createEvent("MouseEvents" / "HTMLEvents") and initEvent / initMouseEvent("click" / "contextmenu"), jQuery's trigger, etc. Nothing makes the default context menu appear.

Is it truly impossible? Does the fact that I'm running "privileged" from a userscript (in Greasemonkey) make any difference? Could I do it from a full-weight Firefox extension?

1 Answer 1

1

You're right, the first three answers, that you linked, are for custom menus/controls.

The fourth answer is correct; you can't activate the browser's context menu(s) -- for the same reasons you can't activate the browser's normal menus... It would be a huge security hole that bad guys would exploit.

Likewise Greasemonkey scripts can't do this either. Greasemonkey scripts have some elevated privileges (only when running in sandboxed mode, as of GM 1.0), but the developers of Greasemonkey have not chosen to make context-menus available. (Nor have I heard of a pressing need for such a feature.)

I'm pretty sure that a full-fledged add-on, could activate context menus (or menu items), but I've never tried it and can't provide code, at the moment.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I think that's as close to a "never nowhere no-how" as I'm going to get. Oh well!
You're welcome, and sorry. I'm browsing through a search and I don't see (yet) that someone's even done this with an add-on/extension. (Doesn't mean it's not possible for an add-on, even if no one's asked about it on SO yet.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.