zhau.09
zhau.09

Reputation: 33

"download" attribute on <a> tag doesn't work on IE, safari or Opera

are there any standard way to make something similar?? I just want a way to download xml files from the server. Please help me!

Upvotes: 3

Views: 8048

Answers (4)

JaffaTheCake
JaffaTheCake

Reputation: 14847

navigator.msSaveBlob(blob, filename)

https://msdn.microsoft.com/sv-se/library/windows/apps/hh772331

Unfortunately I don't know a way to do it in Safari.

Upvotes: 2

hanzi
hanzi

Reputation: 2987

No, as to my knowledge there is no way to do this using HTML.

You have to fix it on the target page. If a certain HTTP header is sent, the browser will offer a page for download instead of displaying it. This should work in every major browser. The necessary header is Content-Type: octet-stream. How you send this depends on your setup.

You can always send it by configuring your web server to do so, but how exacly depends on which web server you are using.

If, on the other hand, your XML file is generated by a PHP script, it's easy. Just add the following line before anything else is written, so preferably to the top of said script:

header('Content-Type: application/octet-stream');

If it's a static XML file... well, you could make a "proxy file" for that. Add a PHP file with the following content:

<?php
header('Content-Type: application/octet-stream');
// This "fakes" the file name, so the downloaded file isn't called
// "download_xml_file.php" or whatever you name the script.
header('Content-Disposition: attachment; filename=my_xml_file.xml');
readfile('path_to_the_actual_xml_file.xml');
?>

But try to avoid this hack. It's unnecessary bloat and it will break browser caching.

Upvotes: 3

Dawid Zbiński
Dawid Zbiński

Reputation: 5826

Here you have a table with the browsers and thier compatibility with attribute download that Mike posted you in a comment: http://caniuse.com/download

And the actual tag with attribute is (just for sure you typing it right):

<a href="your_path_to_file" download>Download Me!</a>

-- it will work only in firefox, chrome and opera as it is in a table.

Upvotes: 0

Dreamer
Dreamer

Reputation: 35

The download attribute only works in Firefox and Chrome. It will not work with IE, safari or Opera.

Upvotes: -2

Related Questions