<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.
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)
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\"
This is not a code issue. It is your default IE settings
To change the " always open " setting:
EDIT: If you ask me , instead of making any changes in the code i would add the following text " Internet Explorer users: To download file, " Rightclick " the link and hit " Save target as " to download the file."
EDIT 2: THIS solution will work perfectly for you. Its a solution i just copied from the other answer. Im not trying to pass it off as my own
Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"filename.xxx\"
However you must make sure that you specify the type of file(s) you allow. You have mentioned in your post that you want this for any type of file. This will be an issue.
For ex. If your site has images and if the end user clicks these images then they will be downloaded on his computer instead of opening in a new page. Got the point. So you need to specify the file extensions.
For apache2 server:
AddType application/octect-stream .ova
File location will depend on particular version of Apache2 -- ours is in /etc/apache2/mods-available/mime.conf
Reference:
https://askubuntu.com/questions/610645/how-to-configure-apache2-to-download-files-directly
This must be a matter of http headers.
see here: HTTP Headers for File Downloads
The server should tell your browser to download the file by sending
Content-Type: application/octet-stream;
Content-Disposition: attachment;
in the headers
压缩文件(.zip),IE将为用户提供打开或下载文件的选项。
It is known HTTP headers problem with Internet Explorer. Try to edit your server's .htaccess
file (if you use Apache) and include the following rules:
# IE: force download of .xxx files
AddType application/octect-stream .xxx
<Files *.xxx>
ForceType application/octet-stream
Header Set Content-Disposition attachment
</Files>
You could configure this in your http-Header
httpResponse.setHeader("Content-Type", "application/force-download");
httpResponse.setHeader("Content-Disposition",
"attachment;filename="
+ "MyFile.pdf");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.