Click here to Skip to main content
15,881,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This part of code performs quite well for Opera, Mozilla, Chrome, but it cannot perform appropriately in any version of IE
C#
var link = document.createElement("a");
       link.setAttribute("id", id here);
       
       link.setAttribute("href", URL here);
       var NameToDownload = desired name here;
       link.setAttribute("download", NameToDownload);
       link.innerHTML = NameToDownload;


How can a file be downloaded via IE from the server if I know its URL?
Thank you in advance.
Posted
Comments
Dzianis Igaravich Leanenka 3-Jun-15 5:24am    
Oh, Let us forget about IE less than 10 version. The issue should be solved for IE 10,11

As you've discovered, Internet Explorer doesn't support the download attribute:
http://caniuse.com/#feat=download[^]
https://status.modern.ie/adownloadattribute[^]

The only workaround appears to be to use server-side code to specify the Content-Disposition header[^], with the value set to attachment.
 
Share this answer
 
Comments
Dzianis Igaravich Leanenka 3-Jun-15 5:26am    
The attachment is used for IE less than 10 version if I do not make a mistake
Richard Deeming 3-Jun-15 5:28am    
Sending Content-Disposition: attachment will work for any modern browser.
Hmmm, what actually I have found. Such a definition like this one performs well. It performs in an appropriate way only with IE 10 and 11. I
C#
var link = document.createElement("a");
       link.setAttribute("id", id here);

       link.setAttribute("href", URL here);
       var NameToDownload = desired name here;
       
       link.innerHTML = NameToDownload;

But if you prefer to have txt downloaded you'll see the file opened but not saved.
It should be somehow walked around...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900