为什么canvas.toDataURL()抛出一个安全异常? [英] Why does canvas.toDataURL() throw a security exception?

查看:339
本文介绍了为什么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?

推荐答案

规格它说:


每当
canvas元素的origin-clean标志
设置为false时,调用toDataURL()方法,方法
必须引发一个SECURITY_ERR异常。 p>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆