I have a script to draw stuff onto a canvas when an image loads. The
idea is to have a chart of some data, the data is requested by the
user, but along with the data, the page also loads a tiny image and on
image load, I am calling a javascript function to draw stuff onto a
canvas. The bigger idea is to have text data and graphical data with
one click. All this works in Firefox, but not in IE. In IE, the
drawing part works if it initiated by a button click or image click.
It does not work when called from onload in the image. I think it is
because the excanvas.js does not exist until the body.onload event. I
can't fire this when the body loads as the body tag part of the page
is common to all pages in the application.
Below is a simplified version of the code. Am I doing something
wrong? Is there a workaround? Can I fire the script on some other
event? Any other way to get the same effect - get text and chart with
one click?
<html>
<head>
<title>Arc Test</title>
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></
script><![endif]-->
<script>
function drawArc()
{
var ctx = document.getElementById('c').getContext('2d');
ctx.beginPath();
ctx.arc(200, 200, 100, 0, Math.PI, true);
ctx.stroke();
ctx.lineTo(200, 200);
};
</script>
</head>
<body>
<img src="
http://www.expenseregister.com/images/1by1.gif"
onload="javascript:drawArc();" />
<canvas id=c width=400 height=400></canvas>
<p>Test test...</p>
<input type='button' value='For IE' onclick="javascript:drawArc();" /
>
</body>
</html>