IE8 doesn`t get canvas element

585 views Asked by At

I have canvas code like below:

 var canvas = document.getElementById('myCanvas');
  var context = canvas.getContext('2d');


  var imageObj = new Image();

  imageObj.src = 'images/floor1.jpg';


  imageObj.onload = function() {
    context.drawImage(imageObj, 0, 0, 610, 290, 0, 0, 610, 290);
    context.beginPath();
    context.rect(62, 66, 66, 25); /* rectangle F sold */
    context.rect(221, 66, 66, 25);
    context.rect(327, 66, 66, 25);
    context.rect(488, 66, 66, 25);
    context.rect(62, 181, 66, 25);
    context.rect(186, 181, 66, 25);
    context.rect(363, 181, 66, 25);
    context.rect(488, 181, 66, 25);
    context.lineWidth = 2;
    context.strokeStyle = 'black';
    context.stroke();
  var dataURL = canvas.toDataURL("image/png");
    document.getElementById('out').src = dataURL;
  };  

But this doesn`t work in IE8. I try to add explorercanvas code:

   < script src="excanvas.js"></script >

    if (typeof(G_vmlCanvasManager) != 'undefined') {
    myCanvas = G_vmlCanvasManager.initElement(myCanvas);
    }

but this doesn`t work. any ideas?

2

There are 2 answers

0
Stasel On

IE 8 does not support the canvas element.

http://caniuse.com/#search=canvas

1
N K On

Your function seems to be recursive. You attached a function to draw imageObj on load event of same(imageObj). Please fix it by removing recursive call.

More than all above, IE8 not support Canvas

Canvas element ✘
2D context ✘
Text ✘