简体   繁体   English

Angular JS App和JSPDF根本无法在IE中使用

[英]Angular JS App and JSPDF not working in IE at all

I have an application in Angular JS and it is using JSPDF. 我在Angular JS中有一个应用程序,它正在使用JSPDF。

The problem is that generating the PDF works in Chrome, Firefox and Safari but not in IE at all. 问题在于生成PDF可以在Chrome,Firefox和Safari中工作,而不能在IE中工作。 There, I get the following error: 在那里,出现以下错误:

SCRIPT438: Object doesn't support property or method 'trimLeft' 
jspdf.plugin.from_html.js, line 71 character 4

Code in js file for generating the PDF: js文件中用于生成PDF的代码:

 function mainControl($scope) {

    $scope.showtooltip = false;
    $scope.value = 'Generate PDF';

    $scope.hideTooltip = function() {
      $scope.showtooltip = false;
    }

    $scope.toggleTooltip = function(e) {
      e.stopPropagation();
      $scope.value = 'HERE';
      $scope.showtooltip = !$scope.showtooltip;
    }
  }

  function printPDF() {

    var doc = new jsPDF();
    var elementHandler = {
      '#oi' : function(element, renderer) {
        return true;
      }
    };

    var source = window.document.getElementsByTagName("body")[0];

    doc.fromHTML($('#content').get(0), 10, 15, {
      'width' : 190
    });


    doc.setFont("helvetica");
    doc.setFontType("normal");
    doc.setTextColor(198, 0, 24);
    doc.setFontSize(10);
    doc.text(10, 10,  'xxxx');

    doc.output("dataurlnewwindow")  
  }

  var Show = {
    getFromPDF : function() {
      $('#btn-pdf').click(function() {
        printPDF();
      });
    }
  }

  $(function() {
    Show.getFromPDF();
  });

IE does not support the non-standard function trimLeft of String.prototype, for more info check this IE不支持String.prototype的非标准功能trimLeft ,有关更多信息,请检查

Here is a workaround : 这是一种解决方法:

<!--[IF IE]>
<script type="text/javascript">
    if (typeof String.prototype.trimLeft !== 'function') {
        String.prototype.trimLeft = function() {
            return this.replace(/^\s*/,'');
        }
    }
</script>

Here is a working demo: 这是一个工作示例:

 if (typeof String.prototype.trimLeft !== 'function') { String.prototype.trimLeft = function() { return this.replace(/^\\s*/, ''); } } var myString = " YEBO zsdsad sadsad "; console.log("test"); console.log(myString.trimLeft()); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM