1

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.

  • your href point on the string "url" in your code ? or you changed your code with "url" as exemple for your file url ? i think you are looking for this http://stackoverflow.com/questions/2408146/href-image-link-download-on-click – Froggiz Sep 01 '15 at 15:13
  • @Froggiz "url" can be any file url. It is loaded dynamically. –  Sep 01 '15 at 15:15

0 Answers0