2011-06-15 29 views
1

我正在嘗試實現excanvas以確保在IE8以及我們在此處使用的所有其他瀏覽器中使用canvas標籤。我有一個問題getContext在IE8中工作。在DOM中動態創建畫布對象時,我已閱讀了有關需要使用G_vmlCanvasManager.initElement例程的問題,但我甚至無法獲得在IE8中靜態創建的對象。我可以告訴畫布創建正確,因爲邊框出現。所有其他瀏覽器都沒有問題。這裏是代碼:在IE8中獲得excanvas使用getContext的問題

<div align="right"> 
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;"> 
Your browser does not support the canvas element. 
</canvas> 

<script type="text/javascript"> 

var c=document.getElementById("myCanvas"); 
if (typeof window.G_vmlCanvasManager!="undefined") { 
    c=window.G_vmlCanvasManager.initElement(c); 
    var cxt=c.getContext("2d"); 
    }else 
    var cxt=c.getContext("2d"); 

cxt.fillStyle="#FF0000"; 
cxt.fillRect(0,0,150,75); 

</script> 
</div> 

感謝您的任何幫助,你可以給。

+0

的可能重複[可能得到Excanvas在IE 8中運行?](http://stackoverflow.com/questions/941170/possible-to-get-excanvas-to-work-in-ie-8) – Prestaul 2013-07-07 03:07:23

回答

1

找到了解決辦法。把代碼中的頭有有載觸發和工作正常,現在

2

的window.onload或的onLoad =「你畫我猜()」應該工作,same thing

<head> 
    <!--[if lt IE 9]> 
     <script type="text/javascript" src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
     <script type="text/javascript" src="/assets/site/excanvas.min.js"></script> 
    <![endif]--> 
    </head> 

    <figure id="logo" class="body"> 
     <canvas id="logo-canvas" width="490" height="135"></canvas> 
     <script src="canvas.js" type="text/javascript"></script> 
     <script type="text/javascript"> 
     window.onload = function() { 
      var c=document.getElementById("logo-canvas"); 
      var cxt=c.getContext("2d"); 
      drawLogo(cxt); 
     } 
     </script> 
    </figure><!-- /#logo -->';