Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File opens instead of downloading in internet explorer in a href link

Tags:

<a href="path/to/file/filename.xxx" download="filename.xxx">filename</a>' 

When i click the link, my filename.xxx should be downloaded.

It works perfectly in chrome. But in Internet explorer, it opens the file instead of downloading. What could be the problem? Is there any properties that is to be added to make it work in ie.

And also i need a file download sample that works for all the browsers.

like image 853
Ebenezar John Paul Avatar asked Jul 31 '13 11:07

Ebenezar John Paul


People also ask

How do I force a file to download instead of open in browser?

Click on "Settings" and you'll see a new page pop up in your Chrome browser window. Scroll down to Advanced Settings, click Downloads, and clear your Auto Open options. Next time you download an item, it will be saved instead of opened automatically.

Why is website downloading instead of opening in browser?

There are tens of reasons which can cause this issue of downloading files instead of opening in browser. But mainly you get this issue due to poor hosting provider, any deflect in cache plugin you're using on your website, or you messed up with the . htaccess file.


2 Answers

The download attribute is not supported in IE (see http://caniuse.com/#search=download%20attribute).

That suggests the download attribute is only supported by firefox, chrome, opera and the latest version of blackberry's browser.

For other browsers you'll need to use more traditional methods to force download. That is server side code is necessary to set an appropriate Content-Type and Content-Disposition header to tell (or trick depending on your point of view) the browser to download the item. Headers should look like this:

Content-Type: application/octet-stream Content-Disposition: attachment;filename=\"filename.xxx\" 

(thanks to antyrat for the copy and paste of the headers)

like image 193
Chris Avatar answered Sep 29 '22 21:09

Chris


It should be fixed on server side. Your server should return this headers for this file types:

Content-Type: application/octet-stream Content-Disposition: attachment;filename=\"filename.xxx\" 
like image 31
antyrat Avatar answered Sep 29 '22 22:09

antyrat