how to use excanvas in jquery

1.1k views Asked by At

I am using excanvas to draw graphical shape and below is my code. While calling the .getContext("2d") method it show the 'undefined' exception in IE7 and IE8.

JS

 var script = document.createElement('script');
                script.src = 'http://canvas-text.googlecode.com/svn-history/r48/trunk/excanvas.js';
                script.type = 'text/javascript';

                var c = document.getElementById("myCanvas");
                context = c.getContext("2d");// getContext is undefined

html

  <canvas id='myCanvas'></canvas>

What I did wrong.. anyone could help on this please?

2

There are 2 answers

2
Umesh On

Try this

var c = document.getElementById("myCanvas");
c= G_vmlCanvasManager.initElement(c);
context = c.getContext("2d");
0
AudioBubble On

You must insert your script element into the DOM tree or it won't be parsed:

document.getElementsByTagName('head')[0].appendChild(script);

(or wherever you want to attach it).

although, I would recommend just using a regular <script> tag when using excanvas and libraries that parses the DOM.