在IE8中让excanvas使用getContext的问题 [英] Problem getting excanvas to use getContext in IE8

查看:330
本文介绍了在IE8中让excanvas使用getContext的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现excanvas,以确保canvas标签在IE8以及我们在这里使用的所有其他浏览器中都能正常工作。我有一个问题让getContext在IE8中工作。我在DOM中动态创建画布对象时已经了解了G_vmlCanvasManager.initElement例程的需要,但是我甚至无法在IE8中使用静态创建的对象。我可以告诉画布是否正确创建,因为边框出现。所有其他浏览器都没有问题。以下是代码:

I am trying to implement excanvas in order to ensure canvas tags work in IE8 as well as all the other browsers we use here. I am having an issue getting getContext to work in IE8. I have read about the need to us the G_vmlCanvasManager.initElement routine when dynamically creating canvas objects in the DOM, however I cannot even get statically created objects to work in IE8. I can tell the canvas is create properly because the border appears. All other browsers have no issues. Here is the code:

<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>

感谢您提供任何帮助。

推荐答案

window.onload或onLoad =drawSomething()应该有效,同样的事情

window.onload or onLoad="drawSomething()" should work, 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 -->';

这篇关于在IE8中让excanvas使用getContext的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆