Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  143] [ 2]  / answers: 1 / hits: 37005  / 13 Years ago, mon, may 30, 2011, 12:00:00

DiveIntoHTML5 Canvas claims that IE9 supports canvas.



However, when I tried doing canvas on IE9, it doesn't work:




Object doesn't support property or method 'getContext'




I'm using IE9.0.8112.16421:



enter



This is the code:



<html>
<head>

</head>
<body style=background:black;margin:0;padding:0;>
<canvas id=canvas style=background:white;width:100%;height:100%;>noob</canvas>
<script>
var img=new Image();
img.onload=function(){
var c=document.getElementById('canvas');
var ctx = c.getContext('2d');
var left,top;
left=top=0;
ctx.drawImage(img,left,top,20,20);
var f=function(){
left+=1;
top+=1;
c.width=c.width;
ctx.drawImage(img,left,top,20,20);
};
setInterval(f,20);
};
img.src=http://a.wearehugh.com/dih5/aoc-h.png;
</script>
</body>
</html>

More From » canvas

 Answers
6

Two things:



The <canvas> tag should having a corresponding closing tag </canvas>. While some browsers will let you get by with just an opening tag, others (such as Firefox, and perhaps IE) won't.



In addition, IE9 requires you to declare an HTML5 doctype to use the canvas tag. You can do this by placing <!DOCTYPE html> at the top of your code.


[#91983] Friday, May 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
teagan

Total Points: 98
Total Questions: 106
Total Answers: 101

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
teagan questions
Fri, Mar 5, 21, 00:00, 3 Years ago
Mon, Feb 15, 21, 00:00, 3 Years ago
;