我使用以下代码将 div 内容保存为 imgae:
function saveDiv() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var mydiv = $(".mydivclass").html();
var data = "data:image/svg+xml," +
"<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%'>" +
mydiv +
"</foreignObject>" +
"</svg>";
var img = new Image();
img.src = data;
img.onload = function () {
ctx.drawImage(img, 0, 0);
}
}
当我调用函数时得到以下信息:
NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMCanvasRenderingContext2D.drawImage]
做错了什么?