0

This is something like simulating the mouse right click to a keyboard key in javascript so as to obtain the context menu and navigate through it to launch the console(Inspect Element).

What i am able to do is.. I can simulate the right click event but it does not generate the context menu on the keypress. When mouse right click is used, it shows the event phase as the bubbling phase whereas on the keypress it shows the event phase as the target phase. Can someone throw any light on this??

Ruchir
  • 313
  • 1
  • 3
  • 9
  • 2
    Standard Windows keyboards have a context-menu key already. – nnnnnn Feb 14 '12 at 05:38
  • I am very well aware of that...But no...I need to map it to a number key say between the ASCII Key Codes of 49 to 57. – Ruchir Feb 14 '12 at 05:41
  • Duplicate question: http://stackoverflow.com/questions/1241478/how-do-i-trigger-the-browser-context-menu-on-an-element-as-if-the-user-right-c – IvanGL Feb 14 '12 at 05:46
  • I did get your point here...but here there is no case of overlaying of elements or anything. I want the same context menu(default) to be launched every time when that key is pressed. Say, u don't have a mouse and u want to launch the console. I know the browser doesn't allow that..but still looking for a way out if possible in any scenario. – Ruchir Feb 14 '12 at 05:58
  • Sounds like an extremely hypothetical scenario that is also extremely browser dependent. My browser opens its console using Cmd+Alt+C. Is your actual question "how to open the browser's console using Javascript"? – deceze Feb 14 '12 at 06:04
  • Hi Deceze, yes it might be browser dependent. but i m specifically asking for Windows google chrome browser and need to map it to a number key(or any key which has a unique ASCII key code) on the keyboard using javascript. Otherwise here also we have shortcut key for the console as Ctrl+Shift+J. – Ruchir Feb 14 '12 at 06:14

1 Answers1

1

What you really want to do is call a function that initiates the (Firebug?) inspect element function. There is no standard javascript function to access the context menu, nor does it seem like a good idea for browsers to allow scripts in web pages access to it, though it might be an extension available in specific browsers for enterprise or controlled environment applications.

For completeness, you can dispatch a click event into the DOM with parameters to emulate a right mouse button click, but that will not open the context menu.

RobG
  • 142,382
  • 31
  • 172
  • 209
  • This is something which i m able to achieve and as u said this doesn't open the context menu. So is there any such extension available for chrome for windows. – Ruchir Feb 14 '12 at 07:08