微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – IE8上的html2canvas和flashcanvas无法正常工作

我使用html2canvas库来制作表格的png图像.

它适用于Chrome,Firefox和Safari.

代码如下:

$('#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);
    }
});

当我用IE8打开页面时,页面不起作用.

我已经读过我应该使用flashcanvas,所以我添加了flashcanvas库并在页面添加了这一行:

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

所以,当我用IE8打开页面时,库flashcanvas.js被加载了!

但问题仍然存在! IE8告诉我:

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

谁能帮我?

解决方法

我不确定canvas元素是如何创建的,但你可能需要在onrendered回调中做这样的事情:

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

请参阅此处的文档:http://flashcanvas.net/docs/usage

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐