0
I converted all images from the site to the format .webp. However, the Safari (Apple) browser doesn’t recognize it yet.
Therefore, I kept all images on the server as well .png. I would like to insert a javascript code that gives a .replace()
in all images of the document HTML
when the browser is Safari, replacing .webp for .png.
Below an example:
<!-- Link para os navegadores Chrome, Edge e Firefox: -->
<img class="imagemsafari" src="images/marcas/Ecommerce-life-detox.webp" alt="Life Detox">
<!-- Link par ao navegador Safari: -->
<img class="imagemsafari" src="images/marcas/Ecommerce-life-detox.png" alt="Life Detox">
So far the only option I found is using the code below. Which unfortunately only changes one id. Goes below:
<script>
if ( navigator.userAgent.indexOf("Safari") != -1 ) {
var str = document.getElementById("imagemsafari").src;
var res = str.replace(/webp/g, "png");
document.getElementById("imagemsafari").src = res;
}
</script>
I was able to explain?
It is not only Safari that does not support .webp ... you should check format support instead of browser
– Lauro Moraes