Как запретить execCommand('SaveAs') открывать новую вкладку или окно

Я должен создать всплывающее окно загрузки в 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);

потому что его записывают в новую вкладку или открывающееся окно

Ниже изображение объясняет..

введите описание изображения здесь

2 ответа

Вместо IEwindow.document.execCommand('SaveAs', true, fileName + ".xls"); используйте ниже фрагмент

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

Включить iframe с идентификатором IframeForExcelExportonIE

<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");
Другие вопросы по тегам