I have a zip file in a predefined location on my web application server. I'm trying to download the file using Javascript and i can get the following to work in FF but not in Chrome. Has anyone come across a better way to do this that is cross browser friendly way (FF/Chrome/IE)? If i could force the Save as prompt even better. Im using the dojo toolkit if it helps
function downloadZip() {
var a = document.createElement("a");
document.body.appendChild(a);
a.href = "/path_to_file/my.zip";
a.click();
}
Try this.
function downloadURI(uri, name)
{
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
}
I have used dojo/request/iframe
for this. This is my exact code:
iframe._currentDfd = null; // Force Dfd to be empty in case prior calls have not been cleared
iframe.post('path_to_file/file.zip',{
data: params,
handleAs: "html"
}).then(function (data) {
console.log('Then called' + data);
}, function (err) {
console.log(err);
});
This works in Chrome, Firefox and IE.
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.