html2canvas code not working IE 11

扶醉桌前 提交于 2020-01-11 10:01:39

问题


I am hoping to use the html2canvas library to make a image of one div and put it in another. So far I have it working wonderfully in Safari, Chrome, and Firefox but not IE (11 is the only version I care about right now).

I am applying it using the code from this jsfiddle from another Stackoverflow question:

var aaaDiv=document.getElementById('aaa');
var ttDiv=document.getElementById('tt');

html2canvas(aaaDiv).then(function(canvas) {
// assign id:avatarCanvas to canvas 
canvas.id='avatarCanvas';
// append canvas to ttDiv
ttDiv.appendChild(canvas);

});

https://jsfiddle.net/m1erickson/wtchz972/

I heard IE doesn't like to 'appendChild', but I am not sure how to proceed from there.


回答1:


The appendChild function has nothing to do with the issue you're facing. appendChild has been supported ever since IE6+

By looking at the html2canvas code, the library happens to make use of the Promises feature which unfortunately is not being supported in any version of IE

http://caniuse.com/#search=promises

(though it is supported in Microsoft Edge)




回答2:


Add this 2 JS - It will automatically provides/replaces Promise if missing or broken.

<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script> 

Source: Comment by Arthez on Roman Canlas's post & https://github.com/stefanpenner/es6-promise



来源:https://stackoverflow.com/questions/35091863/html2canvas-code-not-working-ie-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!