Just open the file's link on the browser and the download will automatically start. Should I always put my JavaScript file in the head tag of my HTML file so that the code is loaded at the start? click for download. Until all modern browsers support the download link attribute, using this hidden form is the best way to generate a file download directly from JavaScript. On the specific link you provided, the page made a request to get.php with a query string hash of the document - the response was a plain PDF file. 27 Apr 2017 Learn how to add a download attribute to a link or Button Module that will allow a file PHP on the server side, modifying the .htaccess file, and/or javascript. a href = "/files/download-file.pdf" download >Download Link a >