Basically, I want to open a context menu on left click itself. Is there anyway to do this using jQuery?
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/
you can record event for right click and trigger whatever event you want to perform on right click.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With