Trying to implement excanvas but getting errors

I am trying to implement excanvas so that my script works in IE as well as in standards compliant browsers. I include jquery, excanvas, and then my script. I create a canvas element as follows:

data.canvas = $(document.createElement('canvas')).attr('width', data.fontwidth * 80 + 'px').attr('height', data.fontheight * 25 + 'px');
$this.append(data.canvas);

But when I try ctx = data.canvas[0].getContext('2d');, I get the error " Object doesn't support this property or method' error on that line. Additionally I'm getting anInvalid argument" on line 160 inside excanvas.js.

My complete code is here . The working page (in everything except IE) is here . The excanvas version I'm using is here .

The update solved the second error. I had to add an element before calling the init function.

+3
source share
2 answers

docs:

getContext . , initElement G_vmlCanvasManager.

var el = document.createElement('canvas');
G_vmlCanvasManager.initElement(el);
var ctx = el.getContext('2d');
+3

.

<canvas width="164" height="164"></canvas>

not

<canvas width="164px" height="164px"></canvas>
+1

All Articles