If Chrome and Firefox do not support the fireEvent method
, you can use the dispatchEvent method instead and directly give a compatible Code.
Trigger click event
function simulateClick(el) {
var evt;
if (document.createEvent) { // DOM Level 2 standard
evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
} else if (el.fireEvent) { // IE
el.fireEvent('onclick');
}
}
Trigger drag event
function simulateDrag(el) {
var evt;
if (document.createEvent) { // DOM Level 2 standard
evt = document.createEvent("MouseEvent");
evt.initMouseEvent ("dragstart", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
} else if (el.fireEvent) { // IE
el.fireEvent('ondragstart');
}
}