【发布时间】:2016-02-10 19:06:21
【问题描述】:
我正在使用 ngCsv 模块 https://github.com/asafdav/ng-csv。
它在 IE9 中不起作用。有些人建议在下面的代码中使用 IE9,但对我来说它不起作用。
查看链接Data URI scheme and Internet Explorer 9 Errors
link: function (scope, element, attrs) {
function doClick() {
var charset = scope.charset || "utf-8";
var blob = Blob !== undefined ? new Blob([scope.csv], {
type: "text/csv;charset="+ charset + ";"
}) : '';
if ( navigator.userAgent.toLowerCase().match(/msie/gi) || navigator.appName.match(/Internet/gi) || navigator.msMaxTouchPoints !== void 0 ){
if( window.navigator.msSaveOrOpenBlob ) {
navigator.msSaveBlob(blob, scope.getFilename());
}else{
var iframe = angular.element('<iframe></iframe>');
iframe[0].style.display = "none";
element.append(iframe);
var doc = null;
if (iframe[0].contentDocument)
doc = iframe[0].contentDocument;
else if (iframe[0].contentWindow)
doc = iframe[0].contentWindow.document;
doc.open("text/plain", "replace");
doc.write([decodeURIComponent(scope.csv)]);
//iframe.focus();
doc.execCommand('SaveAs', true, scope.getFilename());
doc.close();
}
} else {
var downloadLink = angular.element('<a></a>');
downloadLink.attr('href', window.URL.createObjectURL(blob));
downloadLink.attr('download', scope.getFilename());
downloadLink.attr('target', '_blank');
$document.find('body').append(downloadLink);
$timeout(function () {
downloadLink[0].click();
downloadLink.remove();
}, null);
}
}
这里 console.log(doc.execCommand('SaveAs', true, scope.getFilename()));返回 false。
并查看链接ngcsv - Trouble in safari and IE Browsers 不支持 IE9。
请有人为我提供解决方案或建议我以任何其他方式从 AngularJS 中的浏览器下载(数组或对象)CSV 内容。
提前致谢。
【问题讨论】:
标签: angularjs internet-explorer csv