1

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

// 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知识,但不是这个级别!

谢谢。

4

2 回答 2

1

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

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

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

于 2010-01-19T14:30:30.473 回答
0

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

于 2010-01-19T15:58:10.147 回答