In some solutions to “trigger file downloads with JavaScript” questions, the pattern
link = document.createElement('a')
link.click()
is used.
In various places, people report that this did not work in Firefox, suggesting that you need document.body.appendChild(link);
first:
- Download File Using JavaScript/jQuery
- document.createElement(‘a’).click() not working in firefox
It does work in my Firefox 125 which is newer than those answers.
Do the HTML/DOM/JavaScript specs prescribe that .click()
needs to work even without appending to the DOM?
(Bonus points for anybody who can find the commit in Firefox that made this work.)