1

I would like to know what is the best way to detect if the browser is safari and also its version? I want to show something else if the browser is safari and its version is < 13. I was looking at different answers, but did not find a best answer. What I have so far is as below. But it seems it is not applicable to mobile and other things.

  const ua = userAgent.toLocaleLowerCase();
  if (!userAgent) {
    return false;
  }
  
  if (ua.indexOf('safari') !== -1) { 
    return !(ua.indexOf('chrome') > -1 || ua.indexOf('edg'));
  }
bunny
  • 1,797
  • 8
  • 29
  • 58

1 Answers1

0

I strongly recommend this JS Library: https://github.com/bestiejs/platform.js/

It's returns an object:

platform.name; // 'Safari'
platform.version; // '5.1'
platform.product; // 'iPad'
platform.manufacturer; // 'Apple'
platform.layout; // 'WebKit'
platform.os; // 'iOS 5.0'
platform.description; // 'Safari 5.1 on Apple iPad (iOS 5.0)'

Best regards!

Bruno Freire
  • 157
  • 11