8

I've just lauched a HTML5 game application, and I keep receiving 'object doesn't support property or method 'getContext' errors logs from some of my users.

My setup only allows users with Chrome (16<), Firefox (9<) or IE (9<) to play the game. IE (<9) users gets a chromeframe installation in their face.

Its only some of my IE9 users that throw this exception. I've played the game on several windows machines with IE9, both vista and windows 7.

Searching my source, for the function call getContext, I get the same pattern. I create a canvas element using document.createElement, and then i call getContext('2d'), the next line.

var buffer = /** @type {!HTMLCanvasElement} */ (document.createElement('canvas')),
    ctx = /** @type {!CanvasRenderingContext2D} */ (buffer.getContext('2d')),
    draw = function(ctx) {
       /**
        * Alot of drawing calls.
        */
    };
draw(ctx);

Given that alot of my IE9 users run the game as it should, i don't think that this is a problem with my code, but rather some toolbar/plugin or setting in IE9 that is tripping me here.

What do you guys think ?

Firecow
  • 501
  • 1
  • 5
  • 11

4 Answers4

10

After inserting <meta http-equiv="X-UA-Compatible" content="chrome=1, IE=edge"> we have reduced the bug count a lot, we still have a few, but that could be users logging in with weird browsers that the chromeframe install check doesn't catch.

chrome=1 means 'use chrome frame' if its there.

IE=edge means 'use highest possible version of IE'.

So i'll go with that for now.

Firecow
  • 501
  • 1
  • 5
  • 11
  • What changes did u made? @hevi – Illaya Apr 25 '14 at 13:14
  • As per statement [here](http://stackoverflow.com/questions/25557299/internet-explorer-11-disable-display-intranet-sites-in-compatibility-view-via), make sure it is the first meta statement. – B5A7 Feb 16 '17 at 05:03
3

as far as i know IE9 fully supports canvas tag. But user should make sure he is not in compatibility mode. But just to avoid the problem i suggest u using excanvas. If you dont know the how download excanvas and add following link

<!--[if lt IE 9]><script src="../excanvas/excanvas.original.js"></script><![endif]-->
thecodejack
  • 12,689
  • 10
  • 44
  • 59
  • Yeah, but if users are in IE compatibility mode below 9, they should get a Chrome Frame popup, and not be able to play the game before chrome frame is installed... Anyhow I've put in my page header, so that should keep users from running the game in IE quirks mode. I have no intentions of deploying excanvas support. I'll return, when i know if the meta tag have changed anything. – Firecow Feb 16 '12 at 08:00
0

From Instructions

Dynamically created elements If you have created your canvas element dynamically it will not have the getContext method added to the element. To get it working you need to call initElement on the G_vmlCanvasManager object.

var el = document.createElement('canvas');
G_vmlCanvasManager.initElement(el);
var ctx = el.getContext('2d');
kirill.buga
  • 1,129
  • 2
  • 12
  • 26
0

Have you considered the possibility that users don't know which version of IE they are using and are reporting it incorrectly?

x10
  • 3,820
  • 1
  • 24
  • 32