excanvas refusing to work in IE8 despite executing in load event

176 views Asked by At
if(/MSIE (\d+\.\d+); /.test(navigator.userAgent)) {
  var foo = document.getElementById('herd-reports-report-table-div');
  var c = document.createElement('canvas');
  c.setAttribute("width",800);
  c.setAttribute("height",400);
  c.setAttribute("class","mapping");
  foo.appendChild(c);
  c = G_vmlCanvasManager.initElement(c);
} else {
  var c = document.getElementById('herd-report-chart-canvas');
}
var context = c.getContext('2d');

Let's say that I have this code executing in a function on load of a page, and I need a chart to be built. I have included excanvas, yet it won't work. IE8 throws an error at the last line. All I get is "null" error at the appendChild step. Or i get "Object is not supported by this property or method".

I'm at my wit's end. I need this canvas to work in IE8. Somehow.

1

There are 1 answers

0
Orpheus On BEST ANSWER

So I ultimately found the fix for why it (getContext) wasn't working. A few things

  • My conditional comment for including excanvas wasn't correct.
  • Outside that, mine didn't have the support for certain functions called on the canvas element by chart.js, so an update to the excanvas.js fixed that issue.
  • I have everything working on load now, so that issue is also resolved.