Skip to content

Instantly share code, notes, and snippets.

@farmdawgnation
Created May 8, 2012 15:08
Show Gist options
  • Save farmdawgnation/2636061 to your computer and use it in GitHub Desktop.
Save farmdawgnation/2636061 to your computer and use it in GitHub Desktop.
Modernizr Test for VML
// Add a Modernizr check for VML
Modernizr.addTest('vml', function() {
// Adapted from http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser
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)";
var supportsVml = b ? typeof b.adj == "object": true;
a.parentNode.removeChild(a);
return supportsVml;
});
@candrews
Copy link

candrews commented Sep 9, 2013

You can't use document.body inside Modernizr tests - there's a better way to do this. Please see http://www.paulirish.com/2011/surefire-dom-element-insertion/

Instead of:

    var a = document.body.appendChild(document.createElement('div'));

You should do this:

    var a = document.createElement('div');
    var ref = document.getElementsByTagName('script')[0];
    ref.parentNode.insertBefore(a, ref);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment