ktrbhq
Last Updated: February 25, 2016
·
4.638K
· RonnyO

Detect Mobile Safari

Many scripts on the web detect only Safari, or only Apple devices, but return false positives like desktop Safari or Mobile Chrome. Here's my take to detect only Mobile Safari - Save for the next time it drives you crazy with creative & annoying bugs:

/iP(ad|hone|od).+Version\/[\d\.]+.*Safari/i

As a Modernizr test:

Modernizr.addTest('mobilesafari', function() {
  return /iP(ad|hone|od).+Version\/[\d\.]+.*Safari/i.test(navigator.userAgent);
});

Source for Safari-only part: urbz on StackOverflow