html2canvas OnRender failed because of cross domain images

倖福魔咒の 提交于 2019-12-11 12:48:13

问题


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)

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.


回答1:


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)

and there's a proxy in php here: https://github.com/brcontainer/html2canvas-php-proxy



来源:https://stackoverflow.com/questions/17114236/html2canvas-onrender-failed-because-of-cross-domain-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!