繁体   English   中英

如何防止execCommand('SaveAs'打开新标签页或窗口

[英]How to prevent execCommand('SaveAs', from opening new tab or window

我必须在IE中生成一个下载弹出窗口。 我使用下面的代码。 当我单击按钮时,它将打开一个新选项卡,并另存为对话框

 function SaveContents(element) {

            if (document.execCommand) {
                var oWin = window.open("about:blank","_blank");![enter image description here][1]
                oWin.document.write(element);
                oWin.document.close();
                var success = oWin.document.execCommand('SaveAs', false, "FilteredReport.xls")
                oWin.close();

            }

}

如何在不打开新窗口或新标签的情况下显示“另存为对话”框。

我也可以不使用而写一个字符串数据来表现出色

oWin.document.write(element);

因为它被写入打开的新标签或窗口中

下图说明..

在此处输入图片说明

代替IEwindow.document.execCommand('SaveAs', true, fileName + ".xls"); 在以下代码段中使用

if (window.navigator.msSaveOrOpenBlob) {
     blobObject = new Blob([CSV]);
     window.navigator.msSaveOrOpenBlob(blobObject, 'Export.xls');
 }
IEwindow.close();

包含ID为IframeForExcelExportonIE的iframe

<iframe id="IframeForExcelExportonIE" style="display: none"></iframe>

IframeForExcelExportonIE.document.open("txt/html", "replace");
IframeForExcelExportonIE.document.write(cln.innerHTML);
IframeForExcelExportonIE.document.close();
IframeForExcelExportonIE.focus();
sa = IframeForExcelExportonIE.document.execCommand("SaveAs", true, " test.xls");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM