TypeError:对象在IE 11中不支持此操作 [英] TypeError: Object doesn't support this action in IE 11

查看:422
本文介绍了TypeError:对象在IE 11中不支持此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在谷歌浏览器中工作正常,但是在我的代码下面提到的行中,Internet Explorer中出现错误.谁能建议我要对它进行哪些更改才能在IE中工作.

This is working fine in google chrome but getting error in internet explorer at below mentioned line in my code. Can anyone suggest what change do i need to make to it to work in IE.

var file = new File([JSON.stringify($localStorage)], "somefile.txt", {type: "text/plain;charset=utf-8"});

推荐答案

链接到原始答案

为了解释链接,IE 11不支持new File()构造函数,因此您必须使用blob代替.这是一个基本示例:

To paraphrase the link, IE 11 does NOT support new File() constructor, so you'll have to use a blob instead. Here is a basic example:

var myArr = ["Hello", "World", "123", "Howdy"];
var b = new Blob([JSON.stringify(myArr)], {type: "text/plain;charset=utf-8"});
window.navigator.msSaveBlob(b, "OutputFile.txt");

现在您应该会收到一个下载提示.

And now you should receive a download prompt.

这篇关于TypeError:对象在IE 11中不支持此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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