论坛首页 Web前端技术论坛

让人郁闷的window.open[已解决]

浏览 5067 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-08-21  

toolbar

 

在使用Ext.grid.GridPanel时,为了方便导出表格中数据。使用了window.open在新窗口中打开PDF,XLS格式的结果,在firefox2.0.15,3.0.1下正常,在IE6,IE7下返回一个空白页面,从服务器控制台可以看到服务器端是执行了报表导出动作,换成链接方式<a href="export.action?xxx=xxx"> 则可以正确显示结果。

window.open(url) 与 <a href="url" >有这么大区别?export.action是将grid中数据已报表形式显示出来,并可选择导出文件类型。

 

代码如下

 

      var grid = new Ext.grid.GridPanel({
          border:false,
          viewConfig: {
            forceFit:true
          },
          store: store,
          cm: cm,
          sm:gridsm,
          loadMask: true,
          bbar: new Ext.PagingToolbar({
              pageSize: 20,
              store: store,
              displayInfo: true,
              items:['-',{
                  text:'查询范围',
                  menu:contactGridFilterMenu
                },
                filterField,
                filterButton,
                clearButton,
                '-',
                {
                  iconCls:'icon-pdf',
                  tooltip:'将表格导出为PDF文件',
                  handler:function(){
                    var s='';
                    if(store.lastOptions){
                      s+=Ext.urlEncode(store.lastOptions);
                    }
                    if(store.baseParams){
                      if(s===''){
                        s+=Ext.urlEncode(store.baseParams);
                      }else{
                        s+='&';
                        s+=Ext.urlEncode(store.baseParams);
                      }
                    }
                    if(''!==s){
                      s = '?'+s;
                    }
                    window.open("export.action"+s,"_blank");
                  }
                },{
                  iconCls:'icon-xls',
                  tooltip:'将表格导出为XLS文件',
                  handler:function(){
                    var s='';
                    if(store.lastOptions){
                      s+=Ext.urlEncode(store.lastOptions);
                    }
                    if(store.baseParams){
                      if(s===''){
                        s+=Ext.urlEncode(store.baseParams);
                      }else{
                        s+='&';
                        s+=Ext.urlEncode(store.baseParams);
                      }
                    }
                    if(''===s){
                      s = '?type=xls';
                    }else{
                      s = '?' + s +'&type=xls';
                    }
                    window.open("export.action"+s);
                  }
                }
              ]
          })
      });

 

 

 

 

 

   发表时间:2008-09-22  
咋解决的呀?
0 请登录后投票
   发表时间:2008-09-23  
response.setHeader("Content-Disposition", "attachment;filename=\"" + getFileName() + "\"");  
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");  
response.setHeader("Pragma", "public");
response.setDateHeader("Expires", (System.currentTimeMillis() + 1000));
添加了文件头,本来只有第一行,加了后面的就可以了。具体还不是很明白。
感谢fins。从他的一篇回复中找到的
0 请登录后投票
   发表时间:2008-09-23  
我的项目直接在window中嵌入excel了。
pdf还没办法。

--------
0 请登录后投票
   发表时间:2008-09-25  
kimmking 写道
我的项目直接在window中嵌入excel了。
pdf还没办法。

--------

1.兼容firefox?
2.能直接保存在服务器上?
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics