gpt4 book ai didi

javascript - 使用 JQuery 将 IE(Internet Explorer)中的 'save as' 类型更改为 .xls 对话框

转载 作者:行者123 更新时间:2023-12-01 01:26:42 26 4
gpt4 key购买 nike

我在 Internet Explorer 中使用 JQuery 将表格从 HTML 转换为 Excel 文件时遇到问题,出现的对话框显示文件类型为 HTML;我想将文件类型更改为 .xls,我该如何解决这个问题?

这是我的代码:

 $("#btnExport").click(function () {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");

if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
{
txtArea1.document.open("txt/html", "replace");
txtArea1.document.write($('#divExport').html());
txtArea1.document.close();
txtArea1.focus();
sa = txtArea1.document.execCommand("SaveAs", true, "FileName.xls");
}
return false;
});

这样: Save as

最佳答案

你不能这么做。

A security warning关于首先使用此方法的说明:

The "Save as type" field of the dialog always displays "HTML File (*.htm; *.html)," regardless of the content that it is actually saving.

最好避免这种非标准功能。它不适合目的。

关于javascript - 使用 JQuery 将 IE(Internet Explorer)中的 'save as' 类型更改为 .xls 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53707756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com