簡體   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