html2canvas-SecurityError:操作不安全 [英] html2canvas - SecurityError: The operation is insecure

查看:690
本文介绍了html2canvas-SecurityError:操作不安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用html2canvas.js将元素(正文)转换为画布,然后将画布转换为图像. 我的元素包含从跨域加载的图像. 画布从元素创建的效果很好,但是当尝试canvas.toDataURL("image/png");时给出错误SecurityError: The operation is insecure 请帮我解决这个问题. canvas.toDataURL("image/png");不能从跨域加载图像时工作正常.

I have used html2canvas.js in my project for convert my element(body) into canvas and then convert canvas to image. My element contains images that load from cross domain. Canvas create from element is working perfectly, but when try to canvas.toDataURL("image/png"); it gives error SecurityError: The operation is insecure Please help me to solve this issue. canvas.toDataURL("image/png"); is working fine when image not load from cross domain.

谢谢.

推荐答案

这实际上不是html2canvas问题,只是安全问题.

Not really an html2canvas issue--just a security issue.

如果您真的很幸运...

下载跨域图像时,可以使用imageObject.crossOrigin='anonymous'.这要求服务器和浏览器都都是,以允许匿名x域传输.可悲的是,几乎所有服务器和大多数浏览器都不允许.

You can use imageObject.crossOrigin='anonymous' when downloading your cross domain image. This requires both the server and browser to allow anonymous x-domain transfers. Sadly, almost all servers and most browsers don't yet allow.

或者

不要跨网域...在您自己的网站上保留该图片.

Don't go cross-domain...serve that image on your own website.

或者

将图片请求包装在json请求中.这是执行此操作的脚本: http://www.maxnov.com/getimagedata/

Wrap the image request in a json request. Here's a script that does that: http://www.maxnov.com/getimagedata/

这篇关于html2canvas-SecurityError:操作不安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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