由于跨域图像,html2canvas OnRender失败 [英] html2canvas OnRender failed because of cross domain images
问题描述
我想通过html2canvas截图当前页面。但是,代码显示here,然后停止第二个警报函数不触发。
I want a screenshot of the current page through html2canvas. However, the code displays "here" and then stops the second alert function is not triggering
alert("here");
html2canvas(instance.element, {
onrendered: function(canvas) {
alert("here");
instance.options.onPostRender(canvas)
在firebug中出现以下错误:
In the firebug the following error appears:
"NetworkError: 404 Not Found - http://html2canvas.appspot.com/?url=https%3A%2F%2Fwww.otherdomain.com%2Flivezilla%2Fimage.php%3Fid%3D08&callback=html2canvas_1"
我认为它是因为图片来自另一个域,但我没有找到任何解决方案。
I think its because the image is from another domain, but I did not find any solution.
推荐答案
我想你需要一个代理才能使用跨浏览器的图像
html2canvas允许你使用代理它的设置:
I think you need a proxy in order to use cross-browser images. html2canvas allows you to use a proxy on it's settings:
html2canvas(instance.element, {
proxy: 'yourProxyPageOnTheSameServer.php',
onrendered: function(canvas) {
alert("here");
instance.options.onPostRender(canvas)
并且有一个代理PHP在这里:
https://github.com/brcontainer/html2canvas-php-proxy
and there's a proxy in php here: https://github.com/brcontainer/html2canvas-php-proxy
这篇关于由于跨域图像,html2canvas OnRender失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!