Created
May 28, 2013 00:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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