, . IE , "", , canvas javascript, .
Other examples I've seen do this to create their canvas:
var el = document.createElement('canvas');
So, the trick is to simply fool IE by creating something legal and causing canvas to initialize instead.
I used jquery to create an ajax GET for this html block, which I then inserted into the DOM:
<div id="canvasholder">
<canvas id="mycanvas" width="1024" height="768" style="width:1024px;height:768px"></canvas>
</div>
In javascript, after the ajax call has completed and the HTML is inserted, I am initializing my canvas. This is just an interesting snippet from my init function.
...
canvas = $('#mycanvas').get(0);
if(!canvas.getContext)
{
$('#canvasholder').empty();
$('#canvasholder').append(
'<div id="mycanvas" width="1024" height="768"></div>');
canvas = $('#mycanvas').get(0);
if(typeof G_vmlCanvasManager != 'undefined' )
{
canvas = G_vmlCanvasManager.initElement(canvas);
}
}
context = canvas.getContext("2d");
...
Now it works for me in both Firefox and IE7.
source
share