JavaScript simulate right click through code?

Try this instead, reason what things didn't quite work is that the context menu is in fact bound to the oncontextmenu event.

Try this instead, reason what things didn't quite work is that the context menu is in fact bound to the oncontextmenu event. Function contextMenuClick(element){ var evt = element.ownerDocument. CreateEvent('MouseEvents'); var RIGHT_CLICK_BUTTON_CODE = 2; // the same for FF and IE evt.

InitMouseEvent('contextmenu', true, true, element.ownerDocument. DefaultView, 1, 0, 0, 0, 0, false, false, false, false, RIGHT_CLICK_BUTTON_CODE, null); if (document. CreateEventObject){ // dispatch for IE return element.

FireEvent('onclick', evt) } else{ // dispatch for firefox + others return!element. DispatchEvent(evt); } }.

Booo-Yaaa that did the trick, thanks Ieiyou. – Mark Jan 12 '09 at 1:06.

Great question! I did some research, and it seems like you can fire a mouse event like is shown here, and make it a right-click by setting the button or which property to 2 (documented here). Perhaps this code will work: function rightClick(element){ var evt = element.ownerDocument.

CreateEvent('MouseEvents'); var RIGHT_CLICK_BUTTON_CODE = 2; // the same for FF and IE evt. InitMouseEvent('click', true, true, element.ownerDocument. DefaultView, 1, 0, 0, 0, 0, false, false, false, false, RIGHT_CLICK_BUTTON_CODE, null); if (document.

CreateEventObject){ // dispatch for IE return element. FireEvent('onclick', evt) } else{ // dispatch for firefox + others return!element. DispatchEvent(evt); } }.

Here is a more correct version if you do not care about where the context menu gets fired up function fireContextMenu(el) { var evt = el.ownerDocument. CreateEvent("HTMLEvents") evt. InitEvent('contextmenu', true, true) // bubbles = true, cancelable = true if (document.

CreateEventObject) { return el. FireEvent('oncontextmenu', evt) } else { return!el. DispatchEvent(evt) } } If you do, we may have to use the previous one, fix up it's behaviour in IE, and populate the screenX, screenY, clientX, clientY etc appropriately.

Thanks, I don't actually care where it happens, but it might be nice to do so in the future... – Mark Jan 12 '09 at 1:22 If you are using jQuery, right-clicking an element is even simpler: $(your_element). Trigger('contextmenu'); – sunaku Jan 19 at 5:58.

Just for good measure, here is a bit of doco on the parameters: var myEvt = document. CreateEvent('MouseEvents'); myEvt. InitMouseEvent( 'click' // event type ,true // can bubble?

,true // cancelable? ,window // the event's abstract view (should always be window) ,1 // mouse click count (or event "detail") ,100 // event's screen x coordinate ,200 // event's screen y coordinate ,100 // event's client x coordinate ,200 // event's client y coordinate ,false // whether or not CTRL was pressed during event ,false // whether or not ALT was pressed during event ,false // whether or not SHIFT was pressed during event ,false // whether or not the meta key was pressed during event ,1 // indicates which button (if any) caused the mouse event (1 = primary button) ,null // relatedTarget (only applicable for mouseover/mouseout events) ).

I am trying this in firefox and chrome, but dispatching the contextmenu event doesn't make browser to open context menu. Event is triggered because my callback for oncontextmenu is fired, but context menu is still missing. Anybody have an idea, because I used all code samples from above?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions