javascript - How to generate a right-click event in all browsers -


A little context:
Right-click on the app I'm working on Context Menu for some items on the screen. As an existing design, it listens for each object right-click, sends an AJAX request to get reference data of that object, to create popup menu 2 from Dodgeze 0.4.3 (I know!) Right-click to launch the Dojo menu and then generate

I am trying to remove a way to create a right-click event for all browsers . Currently, we only support IE and use the oncontextmenu event.

restriction:

  • No jQuery: (
  • I Dojo on the screen to create menus and avoid AJAX requests All data for the object can not be pre-loaded.

The right click-to-button button parameter is: button = 2.

  if (document.createEvent) {var rightClick = document.createEvent ('MouseEvents') ; RightClick.initMouseEvent ('click on', // type correct, // canBubble truth, // cancel Second window, // view - set to window object 1, // details - mouse # 10, // screen X - Page X coordinate 10, // screen - page y coordinate 10, // clientX - Window X coordinate 10, // Client Y - Window Y coordinate false, // ctrlKey false, // altKey false, // shift key false, // metaca2, // button - 1 = left, 2 = right null // related target); DispatchEvent (rightclick);} and if (document.createEventObject) {// for IE var rightClick = document.createEventObject (); RightClick.type = 'click'; RightClick.cancelBubble = true; RightClick.detail = 1; RightClick.screenX = 10; RightClick.screenY = 10; RightClick.clientX = 10; RightClick.clientY = 10; RightClick.ctrlKey = false; RightClick.altKey = false; RightClick.shiftKey = false; RightClick.metaKey = false; RightClick.button = 2; Document.fireEvent ('onclick', rightClick); }  

I suggest Googleing for 'document.createEvent' and 'document.createEventObject' for more details on APIs from Mozilla and MSDN sites.

Hope that helps!


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -