admin管理员组文章数量:1395021
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");
}
not working in IE 8
but woks in IE 6
what is the problem ? it is alerting "cannot be saved"
help me !!! advance thanks
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");
}
not working in IE 8
but woks in IE 6
what is the problem ? it is alerting "cannot be saved"
help me !!! advance thanks
Share Improve this question edited Mar 25, 2010 at 13:30 Andy E 345k86 gold badges480 silver badges450 bronze badges asked Mar 25, 2010 at 13:18 AnbuAnbu 9533 gold badges10 silver badges16 bronze badges 3- social.msdn.microsoft.com/Forums/en-NZ/iewebdevelopment/thread/… – jholster Commented Mar 25, 2010 at 13:33
- 1 This is almost certainly a permissions problem. Where is this code coming from? In other words, what is the URL for the page that has this code in it? – Pointy Commented Mar 25, 2010 at 13:34
- html table is in one html file & the above code is coming from the javascript file which is in javascript directory (/js/bug_list.js) – Anbu Commented Mar 25, 2010 at 13:39
3 Answers
Reset to default 10The 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:
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.
Sure enough, change the file extension to ".txt" and watch it magically work in IE8.
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).
I know this is an very old thread, but I also faced this problem. You can fix it by adding the following value (depending on the extension of the file beeing downloaded) to your registry.
E.g. for .csv file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.csv]
"PerceivedType"="document"
@MICROSOFT: Shame on you; problem seems to be still unpatched :-)
If you could do this processing server side with PHP or .NET or Java or something, in the http headers set:
Content-Disposition: attachment; filename=file.csv
Which, unfortunately you can't do from JavaScript.
本文标签:
版权声明:本文标题:javascript - execcommand("SaveAs",null,"file.csv") is not working in IE8 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739203325a2147338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论