8

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

greatwolf
  • 20,287
  • 13
  • 71
  • 105
RPB
  • 16,006
  • 16
  • 55
  • 79
  • Possible duplicate: http://stackoverflow.com/questions/6250447/trigger-right-click – James Allardice Aug 30 '11 at 12:10
  • @James Allardice :-That answers are not working in my case. I have already tried that then only i posted this question. – RPB Aug 30 '11 at 12:24
  • Works for me (in Chrome at least): http://jsfiddle.net/interdream/EvZSA/3/ – James Allardice Aug 30 '11 at 12:27
  • Can you show us your implementation, perhaps using jsfiddle.net ? – Manse Aug 30 '11 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. – Scoobler Aug 30 '11 at 12:39
  • Visit this and check it out i can not trigger the event. http://jsfiddle.net/EvZSA/5/embedded/result/ – RPB Aug 30 '11 at 12:42
  • Yes Scoobler somewhat like that – RPB Aug 30 '11 at 12:43
  • Sorry i just shared result, select this even for code sample. http://jsfiddle.net/EvZSA/5/ – RPB Aug 30 '11 at 12:46
  • As far as I understand, you want to display the standard context menu when you left click something? I can't think of a possible solution. – yunzen Oct 04 '11 at 15:50

3 Answers3

6

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/

Jason Dean
  • 9,585
  • 27
  • 36
1

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

Flexo
  • 87,323
  • 22
  • 191
  • 272
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.

Keith
  • 150,284
  • 78
  • 298
  • 434