Skip to content

Instantly share code, notes, and snippets.

@u840903
Last active August 29, 2015 14:03
Show Gist options
  • Save u840903/ee2ccf5b8da106bcb950 to your computer and use it in GitHub Desktop.
Save u840903/ee2ccf5b8da106bcb950 to your computer and use it in GitHub Desktop.
SVG Feature Detection and PNG fallback
// http://toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script/
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
}
if (!supportsSVG()) {
var imgs = document.getElementsByTagName('img');
var dotSVG = /.*\.svg$/;
for (var i = 0; i != imgs.length; ++i) {
if(imgs[i].src.match(dotSVG)) {
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