June 28th, 2013, 05:53 AM
Problem to cancel event on microsoft windows
I try to achieve the following: ensure that by left-clicking on an element of a page, it is the behavior of a right click. Keeping the normal behavior of the right click.
I developed the following code, which seems to work well on Linux but did not have the desired effect on some elements in microsoft windows:
With certain elements such as google search results I have the context menu by left-clicking as desired but the left click has its normal behavior and then redirects me to the site.
var func1 = function(element, event)
var evt = element.ownerDocument.createEvent('MouseEvents');
var RIGHT_CLICK_BUTTON_CODE = 2;
evt.initMouseEvent('contextmenu', true, true, element.ownerDocument.defaultView, 1, event.screenX, event.screenY, event.clientX, event.clientY, false, false, false, false, RIGHT_CLICK_BUTTON_CODE, null);
var func2 = function(Event)
if(Event.button == 0)
var element = Event.srcElement||Event.target;
var cancel = function(event)
event.cancelBubble = true;
event.returnValue = false;
And with Linux, I do not have this problem.
Could you help me?