【发布时间】:2013-12-30 07:15:06
【问题描述】:
鉴于此代码(来自其他人):
var module = angular.module('myApp', []);
module.controller('MyCtrl', function ($scope){
$scope.json = JSON.stringify({a:1, b:2});
});
module.directive('myDownload', function ($compile) {
return {
restrict:'E',
scope:{ data: '=' },
link:function (scope, elm, attrs) {
function getUrl(){
return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], {type: "application/json"}));
}
elm.append($compile(
'<a class="btn" download="backup.json"' +
'href="' + getUrl() + '">' +
'Download' +
'</a>'
)(scope));
scope.$watch(scope.data, function(){
elm.children()[0].href = getUrl();
});
}
};
});
The fiddle example 可以在 chrome 中正常下载。但是点击“下载”链接在 IE11 中没有任何作用。没有错误,没有警告,完全没有响应。
但根据this,IE10 和 11 支持它。
是否有一些 IE 安全设置需要更改或发生了什么?
【问题讨论】:
-
IE 不支持所有 blob mime-types,您是否尝试将其设为纯文本并查看是否有效?
-
我也有同样的问题,我用
text/plain试过了,没用。有趣的是,我可以右键单击,将目标另存为,这样就可以了。
标签: javascript html internet-explorer angularjs bloburls