vhxurg
Last Updated: February 25, 2016
·
1.309K
· herschel666
4f965f0d32998cdf5b3576241aff3929

PNG-Fallback for SVG-Images

Inspired by this snippet: http://codepad.co/s/02aac9, I wrote an alternate version that doesn't depend on jQuery for replacing all SVG-suffixes with the PNG-suffix on inline-images in the markup of a site.

One just has to provide the referenced fallback-images.

var rSvg = /\.(svg)$/;

if ( !Modernizr.svg ) {
  for ( var i = 0, img; img = document.images[i]; i += 1 ) {
    if ( !rSvg.test(img.src) ) continue;
    img.src = img.src.replace(rSvg, '.png');
  }
}

The only dependency is Modernizr.

(https://gist.github.com/herschel666/5024092)

Say Thanks
Respond