javascript - Create a variable using document.createElement('a') and apply click on it without appending it to DOM -


i creating anchor element using jquery/javascript. using method:

var = document.createelement('a'); a.href = '/files/target.pdf'; a.download = true; 

but how can perform click event on without appending/prepending dom? intention pretty simple. want let user download file instead of opening in browser , that's why want avoid window.location = '/files/target.pdf'; function.

please me.

thanks.

well, can trigger "click" this:

var anchor = document.createelement('a'); anchor.href = 'http://gutfullofbeer.net/mozilla.pdf'; anchor.download = true;  var evt = document.createevent('mouseevents'); evt.initmouseevent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);  anchor.dispatchevent(evt); 

however, when in firefox, pdf file that's shown in firefox's built-in pdf viewer. (chrome seems "right" thing, show "save ..." dialog.)


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -