tags:

views:

141

answers:

2

I found the following in a previous post but need some help with it:

// 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;
} 

I would like to use the code to divert users to an alternative page when VML is not supported. Please could somebody show me how to write and implement the code to divert, say, to a page called alternative.html.

I have some knowledge of javascript but not this level!

Thanks.

A: 

You can just make a call to that function provided by Google, and it will return true if VML is supported and false if not. Don't forget, you will still need to add the xmlns for VML somewhere in your HTML.

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

Also, I would recommend using a cross-browser library for drawing vector graphics. There's a few to choose from in this blog post: Canvas/SVG/VML Drawing Roundup.

Andy E
Thanks Andy for such a quick response, I am having difficulty getting it to work. If I post the google code and the following in an external js file:function redirectNoVml() {if (!supportsVml()) { window.location = "../no-vml.htm"; }}and then call redirectNoVml() in the head of my html page,Would you expect this to work ?Thanks
Martin
IE is showing the following error:Message: 'document.body' is null or not an object
Martin
Hi Martin. That error is occurring because the `<body>` tag hasn't finished loading yet. You need to either put your script after the body tag or in the onload event.
Andy E
Andy, yes this was the problem, thanks.
Martin
A: 

VML is only supported in Internet Explorer (as of 5.0) and is not supported in any other browser. So checking for IE should be just enough. This can be done in many ways, for example: !!document.namespaces

Sergey Ilinsky
Currently I just check for IE as you suggest, however I belive there are custom installations of IE where VML is not supported. There are also browsers that appear as IE which may not support it?
Martin
Use ie=!-[1,] to check for Trident. As for the custom installations, I doubt they can be very different - VML is part of the browser.
Sergey Ilinsky
Interestingly enough, I recently had a discussion with a Microsoft employee (from the Desktop Gadgets team) regarding VML and he advised me against relying on it, even in IE. I did find this to be an odd comment, as usually features like VML are left in and just deprecated.
Andy E
I can imagine VML depreacted in IE9 and replaced with SVG.
Sergey Ilinsky
@Sergey Ilinsky: As can I. In fact, I'm expecting canvas support in IE9. A lot of signs are pointing that way, both from my own conversations with staff and with blog posts announcing they're using DirectX for rendering in IE9.
Andy E