Reputation: 1456
I know I'm doing something incredibly stupid so was hoping a second pair of eyes can point out my folly. I'm trying to get the Webshims polyfill to work on a simple canvas test (my first dabble with it). Works great in Chrome and IE9 but testing in IE8 and IE7 (developer tools) I get the error:
Object doesn't support property or method 'getContext'
Here's my code
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="js-webshim/minified/extras/modernizr-custom.js"></script>
<script>
// set options for html5shiv
if(!window.html5){
window.html5 = {};
}
window.html5.shivMethods = false;
</script>
<script src="js-webshim/minified/polyfiller.js"></script>
<script class="example">
window.FlashCanvasOptions = {
disableContextMenu: true
};
$.webshims.setOptions({
waitReady: false
});
$.webshims.polyfill();
</script>
</head>
<body>
<canvas id="my-canvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
var ctx = $('#my-canvas').getContext('2d');
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10, 10, 55, 50);
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
ctx.fillRect (30, 30, 55, 50);
window.FlashCanvasOptions = {disableContextMenu: true};
$.webshims.setOptions('canvas', {type: 'excanvas'});
</script>
</body>
</html>
If I wrap the canvas code in a jquery ready function I don't get an error, but I don't get the canvas rendered either.
$(function(){
var ctx = $('#my-canvas').getContext('2d');
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10, 10, 55, 50);
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
ctx.fillRect (30, 30, 55, 50);
});
I've tested it in BrowserStack with the same results. What am I doing wrong? I'm happy to have my dimness exposed for all to see..!
Upvotes: 1
Views: 423
Reputation: 7511
It's been a long time, but perhaps this will help someone.
I was having this exact same error - no errors logged, but nothing was appearing on the canvas either.
This was fixed by adding
<meta http-equiv="X-UA-Compatible" content="IE=7">
Upvotes: 1