Hello there great folks,
I am quite sure it is possible to change the IMAGE extension of an img src… based on the internet browser.
What am i trying to fix here? If Chrome is used by me or client side the image should show “.webp” format only…because Google chrome only supports this extension else show the JPG and PNG and the rest…
How can i do something like this?
<!-- IE, Firefox, Safari -->
<div class="slide">
<img data-src="http://res.cloudinary.com/orangeworx/image/upload//v1437395843/browser-1.png" class="cld-responsive" alt="Browser #1">
</div>
<!-- Chrome only -->
<div class="slide">
<img data-src="http://res.cloudinary.com/orangeworx/image/upload/v1437395843/browser-1.webp" class="cld-responsive" alt="Browser #1">
</div>
How can i slove this… with PHP or JQuery or javascript? Can anybody help?
This is what i have now but it’s no working:
$(document).ready(function(){
var BrowserChrome = window.chrome;
if(BrowserChrome) {
$('data-src[src$=".png"]').each(function(index,element) {
element.src = element.src.replace('.webp');
});
} else {
$('data-src[src$=".webp"]').each(function(index,element) {
element.src = element.src.replace('.png','jpg');
});
}
});
Thanks!