title: How can I download a pdf from a url using javascript?
body: <p>I need to download pdf's from one of our online resources.There is no built in function to batch download.The only way to do it is to navigate to each pdf file, click to open, then click download. 
  There are several thousand files and this would take a very long time to do.
  I got around this in the past using javascript. I gathered all the links to the pdfs, put them in a csv, and had the code loop through each link, download, and move onto the next link. </p>
  
  <p>Unfortunately, I have lost that code and my efforts to recreate it have been unsuccessful. </p>
  
  <p>I have tried everything in this article: <a href="https://stackoverflow.com/questions/34691525/how-to-download-pdf-automatically-using-js?answertab=active#tab-top">How to download PDF automatically using js?</a></p>
  
  <p>I have tried the code from this article (which I'm pretty sure is what I did before): <a href="https://www.convertplug.com/plus/docs/download-pdf-file-forcefully-instead-opening-browser-using-js/" rel="noreferrer">https://www.convertplug.com/plus/docs/download-pdf-file-forcefully-instead-opening-browser-using-js/</a></p>
  
  <p>This is what I think should work...per the second article I referenced above</p>
  
  <pre><code>function download_file(fileURL, fileName) {
  var link = document.createElement('a');
  link.href = fileURL;
  link.download = 'file.pdf';
  link.dispatchEvent(new MouseEvent('click'));
  }
  var fileURL = "link/to/pdf";
  var fileName = "test.pdf";
  download(fileURL,fileName);
  </code></pre>
  
  <p>The code above is just to test download one file from a hardcoded URL. If it worked as intended, when the page is loaded, it should download the pdf from the provided url. Instead, it doesn't do anything on load or refresh.
  Any suggestions?</p>