I have a large html file that I want to download by opening new window. I am currently using iframe which is making the process long, slow and is also blocking the application. Can someone suggest me an alternative to iframe? plase see below code
var window = new Ext.Window({
title: "download",
height: 100,
layout: 'fit',
items: [{
xtype: 'component',
autoEl: {
tag: 'iframe',
src: 'largedata.html'
}
}]
}).show();
You can do it by XMLHttpRequest
and hidden dom element.
Example:
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status == 200) {
var name = xhr.getResponseHeader('Content-Disposition');
var filename = name.split("Attachment;filename=")[1];
var a = document.createElement('a');
a.href = window.URL.createObjectURL(xhr.response); // xhr.response is a blob
a.download = filename; // Set the file name.
a.style.display = 'none';
document.body.appendChild(a);
a.click();
delete a;
}
};
xhr.open('GET', url, true);
xhr.send();
Parameter url
is path to file.
Edit 2020-04-17:
Alternative you can just open window:
window.open(url, '_blank');
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.