简体   繁体   English

document.execCommand('SaveAs',null,'filename.csv')在chrome上不起作用

[英]document.execCommand('SaveAs',null,'filename.csv') is not working on chrome

Right now am using save as command as follows in my client side js file 现在我在客户端js文件中使用另存为命令,如下所示

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

Am not able to save the page when I am trying to save the page using the above command in Google Chrome. 当我尝试使用上述命令在Google Chrome浏览器中保存页面时,无法保存页面。

when the above one is execute "Save As" dialog is supposed to come but am not getting any dialog like that. 当上面的一个执行时,“另存为”对话框应该出现了,但是没有得到这样的对话框。

it is working fine in IE 11 where as it not working in Chrome. 它在IE 11中工作正常,因为在Chrome中无法正常工作。

Please provide inputs on this issue. 请提供有关此问题的意见。

Thanks in advance. 提前致谢。

The document.execCommand('saveas') functionality is supported only in IE and is not supported in Chrome and Mozila . document.execCommand('saveas')功能仅在IE中受支持,而在ChromeMozila中不受支持。

You can force the SaveAs using http header . 您可以使用http标头强制执行SaveAs You have to include the following header in HTTP response of the file to be downloaded: 您必须在要下载的文件的HTTP响应中包含以下标头:

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

Where <file name.ext> is the filename you want to appear in SaveAs dialog (like finances.xls or mortgage.pdf ) - without < and > symbols. 其中<file name.ext>是要显示在“另存为”对话框中的文件名(例如finances.xlsmortgage.pdf )-不带< and >符号。

More info can be found in this link . 在此链接中可以找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 document.execCommand('copy') 命令在 Chrome 中不起作用 - document.execCommand('copy') Command not working in Chrome document.execCommand(&#39;copy&#39;) 不适用于 Chrome - document.execCommand('copy') not working on Chrome Javascript document.execCommand“粗体”在Chrome中不起作用 - Javascript document.execCommand “bold” not working in chrome Chrome 中的 document.execCommand(&#39;heading&#39; ..&#39;) - document.execCommand('heading' ..') in Chrome document.execCommand无法正常工作 - document.execCommand not working properly 为什么 document.execCommand("paste") 在 Google Chrome 中不起作用? - Why is document.execCommand("paste") not working in Google Chrome? document.execCommand('SaveAs', null, 'myFile.html'); 是否有替代方案? 在 chromium 浏览器中 (Microsoft-Edge) - Is there an alternative for document.execCommand('SaveAs', null, 'myFile.html'); in chromium browsers (Microsoft-Edge) 带有隐藏元素的document.execCommand ..SaveAs问题。 - document.execCommand ..SaveAs issue with hidden elements., 在 Google Chrome 中重新启用 document.execCommand(“cut”) - Reenabling document.execCommand(“cut”) in Google Chrome execcommand(“SaveAs”,null,“file.csv”)在IE8中不起作用 - execcommand(“SaveAs”,null,“file.csv”) is not working in IE8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM