Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download attribute on A tag not working in IE

From the following code I'm creating a dynamic anchor tag which downloads a file. This code works well in Chrome but not in IE. How can I get this working

<div id="divContainer">     <h3>Sample title</h3> </div> <button onclick="clicker()">Click me</button>  <script type="text/javascript">      function clicker() {         var anchorTag = document.createElement('a');         anchorTag.href = "http://cdn1.dailymirror.lk/media/images/finance.jpg";         anchorTag.download = "download";         anchorTag.click();           var element = document.getElementById('divContainer');         element.appendChild(anchorTag);     }  </script> 
like image 939
Nipuna Avatar asked Aug 23 '13 04:08

Nipuna


People also ask

Why download attribute is not working in HTML?

The download attribute only works for same-originl URLs. So if the href is not the same origin as the site, it won't work. In other words, you can only download files that belongs to that website. This attribute follows the same rules outline in the same-origin policy.

How do I download using anchor tag?

Approach 1: Using Download attribute The download attribute simply uses an anchor tag to prepare the location of the file that needs to be downloaded. The name of the file can be set using the attribute value name, if not provided then the original filename will be used.

What is download attribute in anchor tag?

The download attribute specifies that the target (the file specified in the href attribute) will be downloaded when a user clicks on the hyperlink. The optional value of the download attribute will be the new name of the file after it is downloaded.

How do I prompt a download in HTML?

HTML: Use the anchor element download attribute to prompt the user to download a resource. The download attribute on an anchor tag pops up a Save dialog to download the resource, instead of navigating to it. e.g. Using an attribute value, such as download="cat-1.


1 Answers

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.

like image 167
EricLaw Avatar answered Oct 06 '22 01:10

EricLaw