gpt4 book ai didi

javascript - document.execCommand ('SaveAs' ,null ,'filename.csv' ) 不适用于 chrome

转载 作者:行者123 更新时间:2023-11-30 06:20:31 25 4
gpt4 key购买 nike

现在在我的客户端js文件中使用save as命令如下

    var csvWindow = window.open("", "_blank");
csvWindow.document.open('text/html');
csvWindow.document.write(text);
csvWindow.document.execCommand('SaveAs', null, 'data.csv');
csvWindow.close();

当我尝试在 Google Chrome 中使用上述命令保存页面时,无法保存页面。

当执行上述操作时,应该会出现“另存为”对话框,但我没有得到任何类似的对话框。

它在 IE 11 中运行良好,但在 Chrome 中无法运行。

请就此问题提供意见。

提前致谢。

最佳答案

document.execCommand('saveas')功能仅在 IE 中受支持,在 ChromeMozila 中不受支持。

你可以强制SaveAs使用 http header 。您必须在要下载的文件的 HTTP 响应中包含以下 header :

Content-Disposition: attachment; filename="<file name.ext>"

在哪里<file name.ext>是您希望在“另存为”对话框中显示的文件名(如 finances.xlsmortgage.pdf )- 没有 < and >符号。

更多信息可以在这个 link 中找到.

关于javascript - document.execCommand ('SaveAs' ,null ,'filename.csv' ) 不适用于 chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53426070/

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