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.
Written by Emanuel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Js
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#