HTML5 Canvas,excanvas.js& IE浏览器。文本未在IE7中显示

时间:2011-05-18 03:36:31

标签: javascript html5 canvas

这个简单的Canvas脚本创建了一个带有边框和文本的矩形。它适用于Chrome和FireFox。但该文本在Internet Explorer 7.0中不起作用。我收录了excanvas.js;因此,矩形和边框显示在IE 7中。但是,文本没有出现在IE 7中。我想知道是否有可能让这个简单的脚本在IE 7和8中工作?

<!DOCTYPE html> 
<html lang="en">
<head>
    <link href = "style.css" type = "text/css" rel = "stylesheet" />
    <script src="js/excanvas.js" type="text/javascript"></script>

    <script type="text/javascript"> 
    function addBox(){
        var c = document.getElementById("myCanvas");
        context=c.getContext("2d"); 

        //Inner rectangle with shadow
        context.fillStyle = 'red';
        context.shadowColor="brown";
        context.shadowBlur = 20;
        context.fillRect(402,227,96.5,48.5); 
        context.shadowColor = null; 
        context.shadowBlur = null;      

        //Outer Rectangle
        context.lineWidth = '5';
        context.strokeStyle='green';    
        context.strokeRect(400,225,100,50); //draws just the edges of a rectangle               

        //font
        context.font = '17px Arial';        
        context.textBaseline = 'top';  
        context.fillStyle    = 'black';
        context.fillText  ('hello', 433, 243);
    }

    </script>
</head>

<body onload="addBox()"> 

    <canvas id="myCanvas" width="900" height="500">Your browser does not support the canvas element.</canvas> <br />
    <script type="text/javascript">     
        c = document.getElementById("myCanvas"); 
        cxt4=c.getContext("2d");
        resetCanvas();
    </script>
</body>
</html>

2 个答案:

答案 0 :(得分:6)

我刚尝试了这个,并得到了相同的结果。然后我发现我正在使用早期版本的excanvas。用this version再次运行代码,它在IE8中运行。没有在IE7上进行过测试,但运气好的话就可以了。

史蒂夫

答案 1 :(得分:0)

当我更改excanvas.js文件时,fillText正在工作 http://canvas-text.googlecode.com/svn-history/r48/trunk/excanvas.js