Extjs利用iframe无弹窗导出下载文件

本文介绍了一种使用ExtJS框架实现的无弹窗文件下载方法。通过iframe模拟加载新窗口,实现文件的平滑下载过程。具体实现涉及日期格式化、条件判断等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

看过很多导出下载的方式,大都是弹出新窗口下载,我倒是一直用iframe来模拟加载新窗口,从而达到下载文件的目的。

下面是最近用extjs时,也是用到的iframe来模拟无弹窗下载

if (exportForm.getForm().isValid()) {
                        var winobj = Ext.getCmp("exportpopwin");
                        if (winobj) {
                            winobj.destroy();
                        }
                        var startDate, startTime, endDate, endTime;
                        startDate = new Date(Ext.getCmp("exportstartdate").getValue()).format("Y-m-d");
                        startTime = Ext.getCmp("exportstarttime").getValue();
                        endDate = new Date(Ext.getCmp("exportenddate").getValue()).format("Y-m-d");
                        endTime = Ext.getCmp("exportendtime").getValue();

                        var targetWin;
                        switch (dataType) {
                            case 0:
                                targetWin = new Ext.Window({
                                    id: "exportpopwin",
                                    layout: "fit",
                                    width: 0,
                                    height: 0,
                                    html: "Exporting...<iframe scrolling='auto' frameborder='0' width='1px' height='1px' src='export.aspx?dt=0&sd=" + startDate + "&st=" + startTime + "&ed=" + endDate + "&et=" + endTime + "'></iframe>"
                                });
                                break;
                            case 1:
                                targetWin = new Ext.Window({
                                    id: "exportpopwin",
                                    layout: "fit",
                                    width: 0,
                                    height: 0,
                                    html: "Exporting...<iframe scrolling='auto' frameborder='0' width='1px' height='1px' src='export.aspx?dt=1&sd=" + startDate + "&st=" + startTime + "&ed=" + endDate + "&et=" + endTime + "'></iframe>"
                                });
                                break;
                        }
                        targetWin.show();
                        targetWin.setVisible(false); //targetWin.toBack();//这个方式把导出窗口隐藏到条件窗口的后面也可以
                    }

 

转载于:https://www.cnblogs.com/alvinzeng/archive/2013/03/05/2944296.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值