Skip to content

Instantly share code, notes, and snippets.

@nauris-m
Created June 11, 2013 09:47
Show Gist options
  • Save nauris-m/5755710 to your computer and use it in GitHub Desktop.
Save nauris-m/5755710 to your computer and use it in GitHub Desktop.
SVG fallback
/* SVG Fallback */
function handleSvgFallback() {
if (!isSvgSupported()) {
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';
}
}
}
}
function isSvgSupported() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment