使用FileSaver在IE11上保存文件 [英] Saving file on IE11 with FileSaver

查看:257
本文介绍了使用FileSaver在IE11上保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FileSaver库( https://github.com/eligrey/FileSaver.js ),并且在IE11上不起作用,对于其他浏览器,我没有问题.

I'm using FileSaver library ( https://github.com/eligrey/FileSaver.js) and does not work on IE11, with other browsers I had no problem.

代码是这样的:

var file = new File(["content"], "sample.xml", { type: "application/xml;charset=utf-8" });
saveAs(file);

执行第一条指令(新)时出现此错误:

I'm getting this error when the first instruction (new) executes:

对象不接受此操作"

"the object does not accept this action"

git hub上有一个未解决的问题,但实际上没有解决方案,我正在寻找一种应在IE11上正常工作的解决方法,如下所示:

There's an open issue on git hub, but actually with no solution, I'm looking for a workaround that should work on IE11, like this:

try {
                var file = new File([msg.d], "test.xml", { type: "application/xml;charset=utf-8" });
                saveAs(file);
     } catch (err) {
                // Code that works on IE11 ....
     }

任何帮助都应得到赞赏.

Any help should be appreciated.

推荐答案

http://caniuse.com/#搜索=文件 [2]某些浏览器不支持File构造函数.

http://caniuse.com/#search=file [2] Some browser don't support the File constructor.

获取文件实例的唯一方法是通过input[type=file]

The only way you can get a File instance is through input[type=file]

与其将它包装在try/catch中,还不如不这样做:

instead of wrapping it around a try/catch why not just do this:

var blob = new Blob(['content'], { type: 'application/xml' });
saveAs(blob, fileName);

这篇关于使用FileSaver在IE11上保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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