【问题标题】:TypeError: Object doesn't support this action in IE 11TypeError:对象在 IE 11 中不支持此操作
【发布时间】:2018-06-01 13:13:03
【问题描述】:

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

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

【问题讨论】:

标签: javascript angularjs google-chrome cross-browser internet-explorer-11


【解决方案1】:

Link to original answer

为了解释链接,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");

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 2011-05-04
    • 2015-10-24
    相关资源
    最近更新 更多