8

Basically, I want to open a context menu on left click itself. Is there anyway to do this using jQuery?

9
  • Possible duplicate: stackoverflow.com/questions/6250447/trigger-right-click Commented Aug 30, 2011 at 12:10
  • @James Allardice :-That answers are not working in my case. I have already tried that then only i posted this question. Commented Aug 30, 2011 at 12:24
  • Works for me (in Chrome at least): jsfiddle.net/interdream/EvZSA/3 Commented Aug 30, 2011 at 12:27
  • Can you show us your implementation, perhaps using jsfiddle.net ? Commented Aug 30, 2011 at 12:29
  • @James Allardice I think what Rinkalkumar wants is for the default context menu that shows on right click to appear when the user left clicks on an object. Commented Aug 30, 2011 at 12:39

3 Answers 3

6
+25

You can't. JavaScript does not have that access to the browser. Instead you could create your own custom context menu and try to give it the behavior choices you want from the normal context menu (Back, forward, etc). Of course, some of those may be restricted (like copy/paste).

http://labs.abeautifulsite.net/projects/js/jquery/contextMenu/demo/

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

Comments

1

you can record event for right click and trigger whatever event you want to perform on right click.

Comments

1

You can't trigger the right click, but you can trigger a keypress using .trigger()

Shift + F10 should trigger the context menu on Windows, something like...

function openContextMenu() {
  jQuery.event.trigger({ type: 'keypress', which: 121, shiftKey: true });
}

Also there's a context-menu key (on the right before CTRL on 104+ key keyboards) that I think might be keycode 93:

function openContextMenu() {
  jQuery.event.trigger({ type: 'keypress', which: 93 });
}

Update

Actually these just simulate the event - any JS events for that event fire, but the actual key doesn't get sent.

You can do this with an ActiveX object:

// ActiveX object
var shell = new ActiveXObject("WScript.Shell");

// Send SHIFT+F10
shell.SendKeys("+{F10}");

However that component is marked as not safe for scripting and is IE only, so that solution is only really practical for intranets and the like.

2 Comments

I could not make either of these solutions to work. Did you try them?
@Jason Dean - no, they're really just a starting point, but I figured it was worth contributing.

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.