是我 sleep 不足还是什么?以下代码
var frame=document.getElementById("viewer");
frame.width=100;
frame.height=100;
var ctx=frame.getContext("2d");
var img=new Image();
img.src="http://www.ansearch.com/images/interface/item/small/image.png"
img.onload=function() {
// draw image
ctx.drawImage(img, 0, 0)
// Here's where the error happens:
window.open(frame.toDataURL("image/png"));
}
抛出这个错误:
SECURITY_ERR: DOM Exception 18
这绝对行不通!谁能解释一下,好吗?
最佳答案
在specs它说:
Whenever the toDataURL() method of a canvas element whose origin-clean flag is set to false is called, the method must raise a SECURITY_ERR exception.
如果图像来自另一台服务器,我认为您不能使用 toDataURL()
关于javascript - 为什么 canvas.toDataURL() 抛出安全异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2390232/