I have this very simple code to load an image on a canvas. Can you tell my why I have to click twice the button to have the image loaded? (I'm using chrome)
<!DOCTYPE html>
<html>
<body>
<canvas id="c" width="200" height="200"></canvas>
<script type="text/javascript" src="T4_referencing.js"></script>
<input id="b" type="button" onclick="display()"></input>
</body>
</html>
T4_referencing.js
function display(){
var canvas=document.getElementById("c");
var ctx=canvas.getContext("2d");
var im = new Image;
im.src="T3default200x200.png";
ctx.drawImage(im,0,0);
}
Thanks!