问题描述
我使用的是最新版本的 ANGULAR,我只想在下载完成后关闭窗口。
它应该是这样工作的:当用户点击一个链接时,它会打开这个窗口,使下载开始,然后在下载完成时关闭,这样窗口的关闭不会停止下载。
我为除 IE11 之外的主要浏览器解决了所有这些问题,但我真的需要它在 IE11 上工作。
这就是我所拥有的:
startDownload(filename: string,filecontent: string) {
let blob = DownloadUtils.b64toBlob(filecontent,"application/pdf");
let blobUrl = window.URL.createObjectURL(blob);
var downloadID = (new Date()).getTime();
var a = document.createElement('a');
a.setAttribute('href',blobUrl + "#downloadID=" + downloadID);
a.setAttribute('download',filename);
this.cookiePattern = new RegExp(("downloadID=" + downloadID),"i");
this.checkCookies();
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(blobUrl);
}
checkCookies() {
if (document.cookie.search(this.cookiePattern) >= 0) {
open('','_self').close(); // download complete -> close window
return;
}
setTimeout(this.checkCookies,500);
}
我猜 IE11 的问题在于它不允许下载 blob URL。
IE11 强制使用:
window.navigator.msSaveBlob(blob,filename);
但是有了这个,我不能使用 queryString "downloadID" 来检测下载的结束。
我也尝试过 FileSaver.js,但没有奏效。
我也尝试设置:
a.setAttribute('href','data:application/pdf;base64,' + filecontent + "#downloadID=" + downloadID);
哪个有效,除了再次在 IE11 上。我收到此错误:
“传递给系统调用的数据区域太小。”
我可以为 IE11 使用超时,但我不想。
你能帮忙吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)