I am looking for a solution to show different types of images based on the browser type. I want to show png files in case the browser is safari and webp files in case the browser is not safari.
I think this thread already delivers the right js code: How to detect Safari, Chrome, IE, Firefox and Opera browser?
// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification));
How can I call the result in a hugo if statement?
Somehow like this:
{{ $safari := isSafari }}
{{ if eq safari true }}
<img src="{{ "img/bannerphone.png" | absURL }}" alt="phone">
{{ else }}
<img src="{{ "img/bannerphone.webp" | absURL }}" alt="phone">
{{ end }}
Thanks and Regards