- 1 year ago
How do i pass a filename using javascript to a MS Windows, window after clicking a download link in web page? [duplicate]
This can be achieved using the download
attribute of the <a>
tag in HTML. Here's an example of how you can create a link that allows the user to download a file and specify the filename using JavaScript:
html<a id="download-link" href="/path/to/file.pdf" download>Download File</a>
In this example, the href
attribute specifies the path to the file you want to download, and the download
attribute tells the browser to download the file instead of navigating to it. To specify a custom filename, you can set the download
attribute to the desired filename:
javascriptvar filename = "custom_filename.pdf";
document.getElementById("download-link").setAttribute("download", filename);
This will change the download link to download the file with the name "custom_filename.pdf" instead of the original filename. Note that the download
attribute is not supported in some older browsers, so you may need to use a server-side script to handle the file download and set the filename.