为什么 canvas.toDataURL() 会抛出安全异常? [英] Why does canvas.toDataURL() throw a security exception?
本文介绍了为什么 canvas.toDataURL() 会抛出安全异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是我睡眠不足还是什么?下面这段代码
Did I not get enough sleep or what? This following code
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
这绝对行不通!谁能解释一下吗?
There's no way this shouldn't work! Can anyone explain this, please?
推荐答案
在 specs 它说:
每当一个的 toDataURL() 方法其原点清洁标志的画布元素设置为 false 被调用,该方法必须引发 SECURITY_ERR 异常.
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()
If the image is coming from another server I don't think you can use toDataURL()
这篇关于为什么 canvas.toDataURL() 会抛出安全异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文