下载完成后如何关闭窗口?

问题描述

我使用的是最新版本的 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);
}

我的灵感来自:https://laracasts.com/discuss/channels/javascript/using-javascript-to-check-if-a-file-has-been-downloaded

我猜 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...