Skip to content

Instantly share code, notes, and snippets.

@toddmotto
Created January 9, 2013 09:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddmotto/4491950 to your computer and use it in GitHub Desktop.
Save toddmotto/4491950 to your computer and use it in GitHub Desktop.
SVG feature detection script, with SVG to PNG fallback and HTML classes
// SVG custom feature detection and svg to png fallback
// toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script#update
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
}
if (supportsSVG()) {
document.documentElement.className += ' svg';
} else {
document.documentElement.className += ' no-svg';
var imgs = document.getElementsByTagName('img'),
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