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.

- No comments Not publicly viewable

Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.