this article.
The only changes I made were wrapping it in a closure and combining all the vars to make it smaller. Of course your minifier would do this anyway unless you are using it inline after including Modernizr.
Or you can copy the current version from right here.
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';
}
}
})();
}
I'm a full-stack developer, co-organizer of PHP Vancouver meetup, and winner of a Canadian Developer 30 under 30 award. I'm a huge Open Source advocate and contributor to a lot of projects in my community. When I am not sitting at a computer, I'm trying to perfect some other skill.