html2canvas and flashcanvas on IE8 not working

不羁岁月 提交于 2021-02-08 19:46:15

问题


I use html2canvas library to make a png image of a table.

It works on Chrome, Firefox and Safari.

The code is as follows:

$('#myTable').html2canvas ({     
    onrendered : function(canvas) {                           
        var img = canvas.toDataURL('image/png');
        var newWin = window.open('', '_blank','width=500,height=400');
        var htmlPage = "";
        htmlPage += "<html>";
        htmlPage += "<head>";
        ...
        htmlPage += "</head>";
        htmlPage += "<body>";
        ...   
        htmlPage += "<img src='"+img+"' width='400px'/>";
        ...   
        htmlPage += "</body>";
        htmlPage += "</html>";
        newWin.document.write(htmlPage);
    }
});

When I open the page with IE8 the page does not work.

I have read that I should use flashcanvas, so I added the flashcanvas library and added this row in the page:

<!--[if lt IE 9]>                
   <script type="text/javascript src="../sample/flashcanvas.js"></script>
<![endif]-->

So, when I open the page with IE8, the library flashcanvas.js was loaded!

But the problem remains! IE8 tells me:

"The object does not support the property or the method 'toDataURL'"

Can anyone help me?


回答1:


I’m not sure how the canvas element is created, but you might need to do something like this inside the onrendered callback:

if (typeof FlashCanvas != "undefined") {
    FlashCanvas.initElement(canvas);
}
var img = canvas.toDataURL('image/png');
// etc...

See the docs here: http://flashcanvas.net/docs/usage



来源:https://stackoverflow.com/questions/13875498/html2canvas-and-flashcanvas-on-ie8-not-working

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