Saving file on IE11 with FileSaver

点点圈 提交于 2019-11-30 22:44:16

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

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

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

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

I have found a workaround that works on IE11.

This is the code:

try {
            var file = new File(['content'], fileName, { type: 'application/xml;charset=utf-8' });
            saveAs(file);
} catch (err) {
            var textFileAsBlob = new Blob(['content'], { type: 'application/xml' });
            window.navigator.msSaveBlob(textFileAsBlob, fileName);
}

I hope this will help somebody, working with IE11 consumes time for little thing like this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!