2013-03-20 28 views
1

我知道我正在做一件非常愚蠢的事情,所以希望第二雙眼睛能指出我的愚蠢。我試圖讓Webshims polyfill工作在一個簡單的畫布測試上(我的第一次嘗試)。在Chrome和IE9的偉大工程,但在IE8和IE7(開發人員工具)測試我得到的錯誤:HTML 5無法在IE 8和7中使用Webshim獲取畫布

Object doesn't support property or method 'getContext'

這裏是我的代碼

<!DOCTYPE html> 
<html> 
    <head> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> 
     <script src="js-webshim/minified/extras/modernizr-custom.js"></script> 
     <script> 
      // set options for html5shiv 
      if(!window.html5){ 
       window.html5 = {}; 
      } 
      window.html5.shivMethods = false; 
     </script> 
     <script src="js-webshim/minified/polyfiller.js"></script> 
     <script class="example"> 
      window.FlashCanvasOptions = { 
       disableContextMenu: true 
      }; 
      $.webshims.setOptions({ 

       waitReady: false 
      }); 

      $.webshims.polyfill(); 
     </script> 
    </head> 
    <body> 
     <canvas id="my-canvas" width="200" height="100" style="border:1px solid #c3c3c3;"> 
      Your browser does not support the HTML5 canvas tag. 
     </canvas> 
     <script> 
      var ctx = $('#my-canvas').getContext('2d'); 
      ctx.fillStyle = "rgb(200,0,0)"; 
      ctx.fillRect (10, 10, 55, 50); 

      ctx.fillStyle = "rgba(0, 0, 200, 0.5)"; 
      ctx.fillRect (30, 30, 55, 50); 

      window.FlashCanvasOptions = {disableContextMenu: true}; 
      $.webshims.setOptions('canvas', {type: 'excanvas'}); 
     </script> 
    </body> 
</html> 

如果我在一個jQuery就緒功能我裹帆布碼不要看到錯誤,但是我也沒有看到畫布。

$(function(){ 
    var ctx = $('#my-canvas').getContext('2d'); 
    ctx.fillStyle = "rgb(200,0,0)"; 
    ctx.fillRect (10, 10, 55, 50); 

    ctx.fillStyle = "rgba(0, 0, 200, 0.5)"; 
    ctx.fillRect (30, 30, 55, 50); 
}); 

我在BrowserStack中測試了它,得到了相同的結果。我究竟做錯了什麼?我很高興讓我所有人都看到我的朦朧..!

+0

我想, - 由第二代碼片斷看到。我沒有得到一個錯誤,但沒有得到任何畫布。無論如何感謝... – ComfortablyNumb 2013-03-20 16:35:12

回答

0

您必須刪除waitReady或將其設置爲true。

1

這已經很長時間了,但也許這會幫助別人。

我有這個完全相同的錯誤 - 沒有錯誤記錄,但沒有出現在畫布上。

該固定通過將

<meta http-equiv="X-UA-Compatible" content="IE=7"> 
+0

我不記得我做了什麼,但得到它的工作。這是前一陣子!不過謝謝 – ComfortablyNumb 2014-03-19 13:26:50