Skip to content

Instantly share code, notes, and snippets.

@yratof
Created March 21, 2014 16:35
Show Gist options
  • Save yratof/9690234 to your computer and use it in GitHub Desktop.
Save yratof/9690234 to your computer and use it in GitHub Desktop.
Replace SVG with PNG
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, -8) + 'png';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment