问题描述
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.从:
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:
果然,将文件扩展名更改为.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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!