检测对VML的支持,帮助应用之前的帖子

时间:2010-01-19 14:26:34

标签: javascript vml

我在上一篇文章中发现了以下内容,但需要一些帮助:

// For VML detection, here's what google maps does (search for "function Xd"):

function supportsVml() { 
  if (typeof supportsVml.supported == "undefined") { 
    var a = document.body.appendChild(document.createElement('div')); 
    a.innerHTML = '<v:shape id="vml_flag1" adj="1" />'; 
    var b = a.firstChild; 
    b.style.behavior = "url(#default#VML)"; 
    supportsVml.supported = b ? typeof b.adj == "object": true; 
    a.parentNode.removeChild(a); 
  } 
  return supportsVml.supported;
} 

我想在不支持VML时使用代码将用户转移到备用页面。请有人告诉我如何编写和实现代码,以转移到名为alternative.html的页面。

我对javascript有一些了解,但不是这个级别!

感谢。

2 个答案:

答案 0 :(得分:1)

您可以只调用Google提供的该功能,如果支持VML则返回true,否则返回false。不要忘记,您仍然需要在HTML中的某处为VML添加xmlns。

if (!supportsVml())
    window.location = "http://somedomain.com/no-vml.html";

另外,我建议使用跨浏览器库来绘制矢量图形。在这篇博文中有几个可供选择:Canvas/SVG/VML Drawing Roundup

答案 1 :(得分:0)

VML仅在Internet Explorer(5.0版本)中受支持,并且在任何其他浏览器中均不受支持。所以检查IE应该就够了。这可以通过多种方式完成,例如:!! document.namespaces