Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigator.userAgent

Tags:

javascript

I am trying to detect if the browser is Safari. If so, only then do something. In all other browsers, do something else:

if ( navigator.userAgent.toLowerCase().indexOf('safari') == -1) {
    //if safari execute some function
} else {
   // if other browsers execute other function
}

However, I guess I am not using the right approach because it's not working. :P

like image 487
Cam Avatar asked Feb 26 '23 02:02

Cam


1 Answers

if(typeof navigator.vendor!='undefined') &&
   navigator.vendor.toLowerCase().indexOf('apple')!=-1){
    ...
}
like image 70
DejanR Avatar answered Mar 08 '23 07:03

DejanR