我正在使用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()));返回假。
并查看链接ngcsv - Trouble in safari and IE Browsers IE9不支持。
请有人向我提供解决方案或建议我从AngularJS中的浏览器下载(数组或对象)CSV内容的任何其他方式。
提前致谢。
答案 0 :(得分:-1)