我必须在 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();
}
}
如何在不打开新窗口或选项卡的情况下显示“另存为”对话框..
我也可以在不使用的情况下将字符串数据写入Excel
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();
关于javascript - 如何防止 execCommand ('SaveAs' 打开新选项卡或窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24120637/