Possible Duplicate:
canvas drawImage doesn't draw images the first time
I have made an web application in which I have made a game, the game doesn't work on first load, it only runs when you refresh the page, on mozilla or chrome it starts again (i.e is normal). the code is as follow:
<!DOCTYPE html>
<html>
<head>
<script>
function init() {
img=new Image();
img.src= "Device-Android.png";
img1= new Image();
img1.src= "background.png";
play=new Image();
play.src="play.png";
canvas1 = document.getElementById('canvas');
//alert("show");
if (canvas1 && canvas1.getContext) {
ctx = canvas1.getContext('2d');
ctx.drawImage(img,0,0,394,726);
ctx.drawImage(img1,37,92,317,477);
ctx.drawImage(play,149,300,70,40);
//alert("show somthing");
ctx.font = "bold 15pt sans-serif";
document.onmousedown = initGame;
}
}
................ remaining functions
</script>
</head>
<body onload="init();">
<center>
<canvas id="canvas" width="387" height="700"> <h1>Memory Game</h1> </canvas>
</center>
</body>
</html>