Canvas created dynamically after using excanvas.js in IE does not support getcontext resolution (GO)
After using Excanvas.js in IE, the dynamically created canvas does not support GetContext's workaround
After introducing Excanvas.js, in IE, the canvas in the document can be used, but if it is created by the CreateElement method is not
var canvas=document.createelement ("Canvas");
if (Canvas.getcontext) {
Alert ("Support GetContext ()");
}
This code does not work under IE, so the Google made this let IE support canvas code probably read it again, know what is going on. Put the code in the Aptana, 10 minutes less, 785 lines of code, but also good, I think, thanks to the previous carefully read the Rhino book in front of the JS Core section 7 times and the canvas and VML understanding it.
Originally, when loading and executing excanvas.js This script code, G_vmlcanvasmanager_.init (); This statement iterates through all the canvas elements in the page and initializes the elements. That is, the standard canvas of those methods assigned to the canvas under IE:
var els = doc.getelementsbytagname ("canvas");
for (var i = 0; i < els.length; i++) {
if (!els[i].getcontext) {
This.initelement (els[i]);
}
}
If this is the original canvas label for the document, then there is no problem, and this script passes the found canvas element as a parameter to the G_vmlcanvasmanager_.initelement () method. However, the canvas created by the CreateElement method is not available because the new canvas element was not found by the time the script was called.
Then the workaround is to invoke the G_vmlcanvasmanager_.initelement () method to initialize the newly created canvas element.
However, G_vmlcanvasmanager_ is defined in an anonymous function () {}, and I have no way to refer to it in the global scope, fortunately, after the Excanvas.js file, there is a sentence,
G_vmlcanvasmanager = G_vmlcanvasmanager_;
Because of the JS function, if a variable is not defined by Var, then the variable is treated as a global variable, so now there is a global variable to reference it.
So, here's the code to fix the problem:
$ (function () {
var canvas=document.createelement ("Canvas");
Document.body.appendChild (canvas);
if ($.browser.msie) {
Canvas=window. G_vmlcanvasmanager.initelement (canvas);
}
if (canvas.getcontext) {alert ("Support");}
});
I'm using jquery here, and I'm going to execute this script after Dom ready.
In addition, remember Canvas=window. G_vmlcanvasmanager.initelement (canvas), before appending the newly created canvas to the document flow: Document.body.appendChild (canvas);
Canvas created dynamically after using excanvas.js in IE does not support getcontext resolution (GO)