javascript - 浏览器问题: Charts are not rendered on IE8

标签 javascript namespaces canvas dojo cross-browser

我们有内部库,它使用 Canvas 在我的应用程序中显示图表。和 dojo 作为脚本语言。一切都很好,但我的图表没有出现在 IE8 中。 我google了一下,发现IE8中存在一些VML问题。

我发现了这个:

var printChart = function(time, freq){
    if (!document.namespaces['g_vml_']) {
            document.namespaces.add('g_vml_', 'urn:schemas-microsoft-com:vml', '#default#VML');
        }

        if (!document.namespaces['g_o_']) {
            document.namespaces.add('g_o_', 'urn:schemas-microsoft-com:office:office', '#default#VML');
        }

 if (freq === undefined) {
        this.freq = "1mi";
    }

    if (time === undefined) {
        this.time = "1dy";
    }
self.reload();
}

现在我试图将其添加到我的 DOJO 代码中,但这会产生问题。 当我执行 document.namespace 时,我收到 Firebug 错误 'document.namespaces is undefined'

问:我们如何解决这个问题,是否有更好的替代方法来解决与浏览器相关的相同基本问题,图表可以在其他浏览器上正确呈现,但不能在 IE8 上呈现,有什么建议吗? ?

更新:

有哪些方法可以处理此类跨浏览器问题?

最佳答案

关于你提到的跨浏览器问题,基本上有两种方法:browser sniffingobject detection 。浏览器嗅探是检测浏览器 vendor 和版本。例如,您可以从navigator对象知道浏览器是IE 8或Firefox 4.0。对象检测是在实际使用对象/函数之前测试它在浏览器上是否可用。

对于您遇到的问题,您可以使用两种方法。例如,您可以使用 dojo.isIE 嗅探浏览器。

if (dojo.isIE == 8) {
    //Your code to add the namespace
}

或者您可以使用:

if (document.namespaces) {
   // Your code to add the namespace
}

关于javascript - 浏览器问题: Charts are not rendered on IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4595596/

相关文章:

递归函数中的 Python 命名空间

javascript - JS 中的径向形状

javascript - 登录后重定向

ruby-on-rails - 命名空间路由到错误的(父) Controller 操作

javascript - 在 Ajax xhr 响应上使用 jQuery.filter 和 jQuery.find 时的不同结果

c# - 命名空间还是程序集?

html 5 Canvas 阴影只有一个边框

javascript - 如何使用 Canvas 创建如下链接的动画?

ReactJS渲染类名中的javascript嵌套函数调用

javascript - 将 append 的相关元素保留在正文中