【问题标题】:In IE9 ngCsv angular module not working在 IE9 ngCsv 角度模块中不起作用
【发布时间】: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


    【解决方案1】:

    长期问题,但如果有人仍然需要,这里有一个解决方案。

    希望他们能尽快为我们所有人合并。

    https://github.com/asafdav/ng-csv/issues/151

    【讨论】:

      猜你喜欢
      • 2018-09-11
      • 1970-01-01
      • 2018-06-07
      • 2015-07-05
      • 2012-03-07
      • 1970-01-01
      • 2020-04-08
      • 2017-11-29
      • 1970-01-01
      相关资源
      最近更新 更多