Skip to content

Instantly share code, notes, and snippets.

@mcbrwr
Last active August 29, 2015 13:56
Show Gist options
  • Save mcbrwr/9345962 to your computer and use it in GitHub Desktop.
Save mcbrwr/9345962 to your computer and use it in GitHub Desktop.
Replace SVG in all image sources with PNG for browsers that don't support it.
# replace "svg" in all image src's with png for browser without svg support
checkA = document.implementation?.hasFeature "http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"
checkB = document.implementation?.hasFeature "http://www.w3.org/TR/SVG11/feature#Shape", "1.0"
if not checkA and not checkB
for image in document.images
image.src = image.src.replace(/\.svg/i, '.png')
// replace "svg" in all image src's with png for browser without svg support
if (
!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") &&
!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Shape", "1.0")
) {
for(var i = 0; i< document.images.length; i++){
document.images[i].src = document.images[i].src.replace(/\.svg/i, '.png')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment