Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created May 28, 2013 00:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save james2doyle/5659710 to your computer and use it in GitHub Desktop.
Save james2doyle/5659710 to your computer and use it in GitHub Desktop.
Modernizr snippet to replace all the image sources with PNG if there is no support for SVG
if (!Modernizr.svg) {
// wrap this in a closure to not expose any conflicts
(function() {
// grab all images. getElementsByTagName works with IE5.5 and up
var imgs = document.getElementsByTagName('img'),endsWithDotSvg = /.*\.svg$/,i = 0,l = imgs.length;
// quick for loop
for(; i < l; ++i) {
if(imgs[i].src.match(endsWithDotSvg)) {
// replace the png suffix with the svg one
imgs[i].src = imgs[i].src.slice(0, -3) + 'png';
}
}
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment