I have implemented a Download
button using the following HTML
code:
<a class="btn btn-primary" href="url" download>Download</a>
When the button is clicked, the file has to be downloaded into the specified location. This seem to be working fine on Chrome
but not on any other browser,
where the file gets opened in a new tab. I have been stuck with this issue for some time now, and couldn't find a proper solution online. My files can be of any type and the code should work fine for all file types.
I also tried using the content-disposition:attachment header
, the problem is that I also have a View
button along with the download button, for opening the file to view in a new tab
<a class="btn btn-primary" href="url" target="_blank">View File</a>
and this wont work if I use the content-disposition:attachment header
.
Is there any way I can use both the view and Download button together on a page and that work fine across all browsers. I am also fine if this has a solution that use javascript, but need to solve this issue somehow.