javascript 类型错误:对象在 IE 11 中不支持此操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47881250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 07:40:04  来源:igfitidea点击:

TypeError: Object doesn't support this action in IE 11

javascriptangularjsgoogle-chromecross-browserinternet-explorer-11

提问by its.me.chand

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.

这在谷歌浏览器中运行良好,但在我的代码中提到的以下行中的 Internet Explorer 中出现错误。任何人都可以建议我需要对其进行哪些更改才能在 IE 中工作。

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

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

采纳答案by Sal Alturaigi

Link to original answer

链接到原始答案

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:

解释一下链接,IE 11 不支持new File()构造函数,因此您必须改用 blob。这是一个基本示例:

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.

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