So I am trying to work out the differences between
link.click()
and
var event = document.createEvent("MouseEvents");
event.initEvent("click", true, false);
link.dispatchEvent(event);
As far as I can tell these should be the same things (however working with my jsfiddle example of exporting a csv from a URI this is not the case as they perform differently from browser to browser)
Using .click() with firefox the popup to download the csv will not show (it will in chrome)
see example -> http://jsfiddle.net/a5E9m/23/
Where as using the Mouse events it will
see example -> http://jsfiddle.net/a5E9m/25/
I think that Firefox has restrictions around the click function on an <a>
element. See here. Whereas when you wire up the mouse event yourself, you are manually adding the click wiring. Also, see here and here.
Also, as Boris Zbarsky pointed out in the comments, the <a>
element does not have a click function on it in the spec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With