0

我正在使用TagCanvas 插件并想在 IE 8 浏览器中对其进行测试,据记载,我为 IE <9 添加了 Exoplorer 画布,我无法初始化画布元素并在 IE 8 中查看它!

     <head>
         <script src="excanvas.js" type="text/javascript"></script>
         <script src="jquery-1.7.2.min.js" type="text/javascript"></script>
            <script src="tagcanvas.js" type="text/javascript"></script>
    <script type="text/javascript">

            window.onload = function () {
                try {
                    TagCanvas.Start('myCanvas');
                } catch (e) {
                    // something went wrong, hide the canvas container
                    alert("cannot load");
                    document.getElementById('myCanvasContainer').style.display = 'none';
                }
            };
     </script>
        </head>
<body>
   <div id="myCanvasContainer">
 <canvas width="300" height="300" id="myCanvas">

  <ul>

   <li><a href="#">test</a></li>
   <li><a href="#">test1</a></li>

  </ul>
 </canvas>
</div>
</body>

我能知道我是否遗漏了 IE 8 支持的 canvas 元素的任何参考吗?

4

1 回答 1

0

看:


ModernizrJavaScript library that detects which HTML5 and CSS3 features您访问者的浏览器支持的。在检测功能支持时,it allows developers to test for some of the new technologies and then provide fallbacks for browsers不支持它们。这就是所谓的feature detection and is much more efficient than browser sniffing.

再次以画布为例,您通常需要对不支持的 IE8 及更低版本进行后备。执行此操作的常用方法是链接到 JavaScript polyfill,例如 HTML 中的 FlashCanvas:

<script src="http://flashcanvas.net/bin/flashcanvas.js"></script>

The problem with this approach is that all browsers will download this script.
这是不必要的should be avoided where possible.

您可以将元素包装<script>在条件注释中,但如果您可以将文件完全排除在标记之外,那么您应该这样做。You can do this using Modernizr.load().

Modernizr has YepNope built into it,因此您可以轻松地测试功能,然后提供 polyfill。

的基本用法.load() function允许您test为一个特征和ask whether it’s true (yep) or false (nope).
在这个例子中Modernizr tests for canvas support, 和if the feature doesn’t exist, then it loads FlashCanvas


Modernizr.load({
  test: Modernizr.canvas,
  nope: 'http://flashcanvas.net/bin/flashcanvas.js'
});

于 2013-01-22T05:55:09.877 回答