我使用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'"
任何人都可以帮助我吗?
答案 0 :(得分:1)
我不确定如何创建canvas
元素,但您可能需要在onrendered
回调中执行类似的操作:
if (typeof FlashCanvas != "undefined") {
FlashCanvas.initElement(canvas);
}
var img = canvas.toDataURL('image/png');
// etc...
请参阅此处的文档:http://flashcanvas.net/docs/usage