1

I can't find a related question to give me an idea about how to do this.

I've seen some topics about how to know if the right-click button was clicked but I'd like to be able to capture the value that's selected on a context menu after right click.

Any idea how I could achieve it?

2
  • I suppose, this is impossible in general. Commented Mar 7, 2012 at 11:29
  • 1
    It's impossible. No events that area visible to JavaScript are directly generated by the user activating options on the context menu. You may get events indirectly: cut, copy and paste will generate events. Commented Mar 7, 2012 at 12:27

1 Answer 1

1

In a browser, you can:

a) ignore the right click and let the browser itself handle it (which usually means a context menu will be shown)

XOR

b) handle the right click yourself, which means that the browser won't show its context menu.

You can't have both a) and b), they're mutually exclusive. If you want a right-click context menu on a webpage, you need to fake it yourself - for example, see this tutorial and the result.

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

4 Comments

Thank you for the hint! I was not aware of that... The guy who created the page's on holidays for a few weeks but he created a custom context menu. I'll see if with the example I can see how is possible to get the selected value with Javascript. I think it'll be something like alert($(this).text()); but not quite sure yet about the ready or live functions... Thanks for the link again.
Thank you guys, good example to understand how this could be achieved. But as mentioned above I think it's not possible in general.
@mickael: Well, if you already have a custom right-click menu, you need to find out how it works; as it's custom, it could be any way imaginable, and SO can't really help there.
Yes, many thanks. I marked it as resolved as you helped me to understand about how it should work. I've never done anything in JS before so we'll have to wait until the owner is back :) Cheers!

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.