我有同样的问题。我想做的是将画布转换为图像,然后在新选项卡中打开它。我发现转换它不是问题,但在新链接中打开是问题。我通过生成图像来解决它,将其放入 img 标签中,然后将其包含在新页面中。然后我使用本教程打开了新页面 - http://www.javascripter.net/faq/writingt.htm
这是我所做的
var canvas = document.getElementById('canvas1');
var dataURL = canvas.toDataURL();
var width = parseInt($("#main").width()); //main is the div that contains my canvas
var height = parseInt($("#main").height());
newWindow("<img src=\"" + dataURL + "\"/>");
function newWindow(content) {
top.consoleRef = window.open("", "Organisational Structure",
"width="+width+",height="+height
+ ",menubar=0"
+ ",toolbar=1"
+ ",status=0"
+ ",scrollbars=1"
+ ",resizable=1")
top.consoleRef.document.writeln(
"<html><head><title>Console</title></head>"
+ "<body bgcolor=white onLoad=\"self.focus()\">"
+ content
+ "</body></html>"
)
top.consoleRef.document.close()
}