javascript - Html2Canvas not working on Google Chrome - Stack Overflow

I have the following code, it works fine on Firefox but the image is not being rendered on Chrome for s

I have the following code, it works fine on Firefox but the image is not being rendered on Chrome for some reason, any ideas?

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Html2Canvas</title>
<script type="text/javascript" src="jquery-1.6.3.js"></script> 
<script type="text/javascript" src="html2canvas.js"></script> 
<script type="text/javascript" src="jquery.plugin.html2canvas.js"></script> 
</head>
<body>
testing
<img src="someImage.jpg"/>
<script type="text/javascript">
window.onload = function() {
    html2canvas( [ document.body ], {
        onrendered: function( canvas ) {
              document.body.appendChild( canvas );
            }
    });
};
</script>
</body>
</html> 

I have the following code, it works fine on Firefox but the image is not being rendered on Chrome for some reason, any ideas?

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Html2Canvas</title>
<script type="text/javascript" src="jquery-1.6.3.js"></script> 
<script type="text/javascript" src="html2canvas.js"></script> 
<script type="text/javascript" src="jquery.plugin.html2canvas.js"></script> 
</head>
<body>
testing
<img src="someImage.jpg"/>
<script type="text/javascript">
window.onload = function() {
    html2canvas( [ document.body ], {
        onrendered: function( canvas ) {
              document.body.appendChild( canvas );
            }
    });
};
</script>
</body>
</html> 
Share Improve this question edited Dec 22, 2012 at 17:37 the_marcelo_r asked Dec 22, 2012 at 16:42 the_marcelo_rthe_marcelo_r 1,85623 silver badges36 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

The image may not have loaded before the html2canvas attempts to draw it. Attempting to draw an image that hasn't loaded silently does nothing, so you get nothing.

Try wrapping your html2canvas call in a window.onload handler. NOT jQuery's ready because you NEED the code to run ONLY when all images etc. have fully loaded.

It will not work if you run this html file without any web server . If you are playing around on your PC then install XAMPP or any other web server (Easiest option http://www.apachefriends/en/xampp.html) and put the image ,JavaScript and HTML code in C:\xampp\htdocs (if C dirive is your installation drive) and run using the server. I have tested it in Chrome and its working.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745165292a4614592.html

相关推荐

  • javascript - Html2Canvas not working on Google Chrome - Stack Overflow

    I have the following code, it works fine on Firefox but the image is not being rendered on Chrome for s

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信