2

How detect Safari browser ONLY on desktop ?
I want to know only when user is on desktop and not with mobile device.

var ua = navigator.userAgent.toLowerCase(); 
if (ua.indexOf('safari') != -1) { 
    //find safari
}

I noticed that Desktop Safari doesn't support input[type=date] but mobile safari (the name is webkit ?) yes. So for me is important understand when user is on desktop.

Thanks a lot and sorry for my english.

Borja
  • 2,567
  • 5
  • 24
  • 48
  • Possible duplicate of https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery – Stefan Blamberg Sep 06 '18 at 13:01
  • @StefanBlamberg how can be duplicate if in "your question" is how detect mobile device with jquery while in my quesion how detect only desktop safari ?! – Borja Sep 06 '18 at 13:04
  • I am a bit confused, why can't you use the answers provided there to make sure that it is not a mobile safari version? e.g. `if (/Mobi|Android/i.test(navigator.userAgent)) { // mobile! }` as in https://stackoverflow.com/a/24600597/5843525 – Stefan Blamberg Sep 06 '18 at 13:09
  • Are you only wanting to target the Safari browser; mobile vs desktop? Are you expecting Windows and Mac users or just one or something else? – daddygames Sep 06 '18 at 13:10
  • for me is impostant to know only if is desktop safari, because i have an input type date and safari (on desktop) doesn't support it https://caniuse.com/#feat=input-datetime – Borja Sep 06 '18 at 13:12
  • @Borja Please don't abuse comment flags, nothing here *remotely* qualifies as "harassment, bigotry or abuse". – meager Sep 06 '18 at 13:55

1 Answers1

5
const uA = navigator.userAgent;
const vendor = navigator.vendor;
if (/Safari/i.test(uA) && /Apple Computer/.test(vendor) && !/Mobi|Android/i.test(uA)) {
  //Desktop Safari
}
Stefan Blamberg
  • 806
  • 7
  • 21
  • 2
    chrome has Safari in its user agent and will be detected with this – pscheit Oct 21 '18 at 14:02
  • @P.Scheit Thanks for pointing this out, I updated the answer according to https://stackoverflow.com/questions/3303858/distinguish-chrome-from-safari-using-jquery-browser – Stefan Blamberg Oct 24 '18 at 14:55