All 1 entries tagged Vml

No other Warwick Blogs use the tag Vml on entries | View entries tagged Vml at Technorati | There are no images tagged Vml on this blog

August 23, 2007

Add XML namespace outside of HTML tag

This post is purely for Google’s benefit.

I was trying to find a way of enabling VML in IE without changing the HTML tag and after a lot of searching could not find anything. Turns out it is relatively simple in JavaScript with the following code (totally stolen):

var tmp = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
if(tmp) var isIE = document.namespaces ? 1 : 0;

if(isIE) {
     if(document.namespaces['v'] == null) { 
          var stl = document.createStyleSheet(); 
          stl.addRule("v\\:*", "behavior: url(#default#VML);"); 
          document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); 
     }
}

Hopefully this will help someone else will save themselves some time.