替代Ext.window中的iframe

问题描述 投票:0回答:1

我有一个很大的html文件,我想通过打开新窗口来下载。我目前正在使用iframe,这会使处理过程变得漫长,缓慢,并且也阻塞了应用程序。有人可以建议我替代iframe吗?请参见下面的代码

   var window = new Ext.Window({
                title: "download",
                height: 100,
                layout: 'fit',
                items: [{
                    xtype: 'component',

                    autoEl: {
                            tag: 'iframe',
                            src: 'largedata.html'

                        }
                    }]
            }).show();
javascript extjs
1个回答
0
投票

您可以通过XMLHttpRequest和隐藏的dom元素来完成。

示例:

        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();

参数url是文件的路径。

© www.soinside.com 2019 - 2024. All rights reserved.