Download attribute on A tag not working in IE
Internet Explorer does not presently support the Download
attribute on A
tags.
See http://caniuse.com/download and http://status.modern.ie/adownloadattribute; the latter indicates that the feature is "Under consideration" for IE12.
download attribute on a tag doesn't work on IE, safari or Opera
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.
Anchor Tag Download (Not Working in IE) (href from external link) using jQuery
The download property is supported in Firefox, Opera and Chrome.
Note: The download property is not supported in Internet Explorer, Safari or Opera 12 and earlier versions.
Source: http://www.w3schools.com/jsref/prop_anchor_download.asp
I hate to quote w3schools, I know.
download attribute in `a` tag is not working
The download attribute is not supported in Edge version 12, IE, Safari
10 (and earlier), or Opera version 12 (and earlier).
One reason why it does not work is because your file path is incorrect.
Check if your file does exist.
This is not a correct syntax
attr('download', 'image.jpg');
You should do this instead:
attr("download", true);
Here is a working code:
I used a sample image from w3schools
var data = 'https://www.w3schools.com/images/myw3schoolsimage.jpg';
var $a = $('<a />').appendTo('body');$a.attr('id', 'sample');$a.attr('href', data);$a.attr("download", true);$a.attr('target', '_blank');$a[0].click();$a.remove();
<html><head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script></head><body>
</body></html>
Download Attribute in anchor tag not work in IE9?
Download attribute is not supported by IE.
For more info
Dowload button not working on Internet Explorer
The IE browser not support the Download attribute. You could try to use msSaveOrOpenBlob method to download the file in IE browser.
Try to use the following code:
<script>
function Download(containerid) {
var returnedData = document.getElementById(containerid).innerHTML;
var filename = "hello.txt";
var BOM = "\uFEFF";
if (navigator.msSaveBlob) { // ie block
console.log("found msSaveBlob function - is't IE")
var blobObject = new Blob([BOM + returnedData], { type: ' type: "text/plain;charset=utf-8"' });
window.navigator.msSaveOrOpenBlob(blobObject, "hello.txt");
}
else { // non-ie block
console.log("not found msSaveBlob function - is't not IE")
var a = window.document.createElement('a');
a.setAttribute('href', 'data:text/plain; charset=utf-8,' + encodeURIComponent(BOM + returnedData));
a.setAttribute('download', 'hello.txt');
a.click();
}
}
</script>
Related Topics
Removing Whitespace Between HTML Elements When Using Line Breaks
Why Does Firebug Add ≪Tbody≫ to ≪Table≫
How to Make a Curved Edge Hexagon by Using Css
Printing "≪Html≫" Using Html
How to Add 1Px Margin to a Flex Item That Is Flex: 0 0 25%
How to Create a Marquee Effect
How to Convert an HTML Element to a Canvas Element
How to Display Just a Portion of an Image in Html/Css
How to Apply CSS Page-Break to Print a Table With Lots of Rows
Why Does Html5 Form-Validation Allow Emails Without a Dot
Is a Div Inside a Td a Bad Idea
Css Overflow:Hidden With Floats
What Character Represents a New Line in a Text Area
Should I Put Input Elements Inside a Label Element
How to Write a CSS Selector Selecting Elements Not Having a Certain Class or Attribute
Getting the Source HTML of the Current Page from Chrome Extension