01 <canvas id="myCanvas" width=”300” height=”200” style="border:1px solid #c3c3c3;">
02 Your browser does not support the canvas element.
03 </canvas>
04 <script type="text/javascript">
05 var myCanvas = document.getElementById("myCanvas");
06 if (!myCanvas.getContext)
07 {
08 alert("Your browser does not support the canvas element.");
09 }
10 else
11 {
12 // do something here
13 }
14 </script>
解析:
上面的Javascript代码通过判断getContext方法是否为空来判断浏览器是否支持canvas标签。