execcommand(" SaveAs",null," file.csv")在IE8中不起作用 [英] execcommand("SaveAs",null,"file.csv") is not working in IE8

查看:122
本文介绍了execcommand(" SaveAs",null," file.csv")在IE8中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var doc = w.document;
doc.open('application/CSV','replace');
doc.charset = "utf-8";
doc.write("all,hello");
doc.close();

if(doc.execCommand("SaveAs",null,"file.csv")) {
    window.alert("saved ");
}else {
    window.alert("cannot be saved");
}

不在IE 8中工作

但在IE 6中工作

有什么问题?警告无法保存

what is the problem ? it is alerting "cannot be saved"

帮助我!!!提前谢谢

推荐答案

这个问题似乎是由Windows XP中修复但在我的Windows中显然没有修补的旧错误引起的7.从 http://support.microsoft.com/kb/929863

The problem seems to be caused by an old bug that was fixed in Windows XP but is apparently unpatched in my Windows 7. From http://support.microsoft.com/kb/929863:


出现此问题是由于 ExecCommand 功能的限制。当您运行使用 ExecCommand 功能和 SaveAs 命令的脚本时,脚本只能保存文本文件类型的文件。

This problem occurs because of a limitation in the ExecCommand function. When you run the script that uses the ExecCommand function together with the SaveAs command, the script can only save a file that is the text file type.

果然,将文件扩展名更改为.txt并在IE8中神奇地观察它。

Sure enough, change the file extension to ".txt" and watch it magically work in IE8.

我想到的唯一解决方法是使用服务器端语言创建CSV文件,然后将其作为下载服务(使用 Content-disposition:attachment 标题)。

The only workaround that comes to mind is to have a server-side language create the CSV file, and serve it up as a download (using the Content-disposition: attachment header).

这篇关于execcommand(" SaveAs",null," file.csv")在IE8中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆