jsPDF和html2canvas兼容IE11

之前写了利用jsPDF和html2canvas做多页PDF导出,但是发现在IE下面不行,存在BUG,也就是Promise未定义的问题,于是也一起处理了一下。
起先我想打算用bluebird.js,但是发现与现有项目代码存在冲突,所以先放弃了,然后采用了第二种方式通过引用polyfill.js可以解决这个问题:

polyfill.js:

(function(t){
   "use strict";if(!t.matches&&t.matchesSelector){
   t.matches=t.matchesSelector}if(!t.matches&&!t.matchesSelector){
   t.matches=function(t){
   var e=document.querySelectorAll(t),n=this;return Array.prototype.some.call(e,function(t){
   return t===n})}}})(Element.prototype);(function(t){
   "use strict";if(typeof t.Promise==="undefined"||t.Promise.toString().indexOf("[native code]")===-1){
   var e="[[PromiseStatus]]";var n="[[PromiseValue]]";var r="pending";var i="internal pending";var o="resolved";var s="rejected";var c=function(t,s){
   if(t[e]===i){
   t=t[n]}if(t[e]===r){
   t.deferreds.push(s)}else{
   t.handled=true;setTimeout(function(){
   var r=t[e]===o?s.onFulfilled:s.onRejected;if(r){
   try{
   a(s.promise,r(t[n]))}catch(t){
   u(s.promise,t)}}else{
   if(t[e]===o){
   a(s.promise,t[n])}else{
   u(s.promise,t[n])}}},0)}};var a=function(t,r){
   if(r===t){
   throw new TypeError("A promise cannot be resolved with it promise.")}try{
   if(r&&(typeof r==="object"||typeof r==="function")){
   if(r instanceof p){
   t[e]=i;t[n]=r;f(t);return}else if(typeof r.then==="function"){
   h(r.then.bind(r),t);return}}t[e]=o;t[n]=r;f(t)}catch(e){
   u(t,e)}};var u=function(t,r){
   t[e]=s;t[n]=r;f(t)};var f=function(t){
   if(t[e]===s&&t.deferreds.length===0){
   setTimeout(function(){
   if(!t.handled){
   console.error("Unhandled Promise Rejection: "+t[n])}},0)}t.deferreds.forEach(function(e){
   c(t,e)});t.deferreds=null};var h=function(t,e){
   var n=false;try{
   t(r,i)}catch(t){
   if(!n){
   n=true;u(e,t)}}function r(t){
   if(!n){
   n=true;a(e,t)}}function i(t){
   if(!n){
   n=true;u(e,t)}}};var l=function(t,e,n){
   this.onFulfilled=typeof t==="function"?t:null;this.onRejected=typeof e==="function"?e:null;this.promise=n};var p=function(t){
   this[e]=r;this[n]=null;this.handled=false;this.deferreds=[];h(t,this)};p.prototype["catch"]=function(t){
   return this.then(null,t)};p.prototype.then=function(t,e){
   var n=new p(function(){
   });c(this,new l(t,e,n));return n};p.all=function(t){
   var e=[].slice.call(t);return new p(function(t,n){
   if(e.length===0){
   t(e)}else{
   var r=e.length;var i=function(o,s){
   try{
   if(s&&(typeof s==="object"||typeof s==="function")){
   if(typeof s.then==="function"<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值