简体   繁体   English

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

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

I have to generate a download pop up in IE. 我必须在IE中生成一个下载弹出窗口。 Iam using the below code. 我使用下面的代码。 when i click on buttton it opens a new tab and the Save as Dialogue box 当我单击按钮时,它将打开一个新选项卡,并另存为对话框

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

            }

}

How can i make the Save as Dialogue box appear with out opening new window or tab.. 如何在不打开新窗口或新标签的情况下显示“另存为对话”框。

Also can i write data of a string to excel with out using 我也可以不使用而写一个字符串数据来表现出色

oWin.document.write(element);

beacuse its getting written to the new tab or window that opens 因为它被写入打开的新标签或窗口中

Below image explains.. 下图说明..

在此处输入图片说明

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

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

include an iframe with ID IframeForExcelExportonIE 包含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