Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a browser is Chrome using jQuery?

I have a bit of an issue with a function running in chrome that works properly in Safari, both webkit browsers...

I need to customize a variable in a function for Chrome, but not for Safari.

Sadly, I have been using this to detect if it is a webkit browser:

if ($.browser.webkit) { 

But I need to detect:

if ($.browser.chrome) { 

Is there any way to write a similar statement (a working version of the one above)?

like image 523
TaylorMac Avatar asked Jun 14 '11 05:06

TaylorMac


People also ask

How do I know what browser I am using Javascript?

To detect user browser information we use the navigator. userAgent property. And then we match with the browser name to identify the user browser. Now call this JS function on page load, and this will display the user browser name on page load.

How do I identify my browser?

In the browser window, hold the Alt key and press H to bring up the Help menu. Click About Google Chrome and locate the version at the top of the window that appears.

How can you detect the client's browser name in Javascript?

You can use the navigator. appName and navigator. userAgent properties. The userAgent property is more reliable than appName because, for example, Firefox (and some other browsers) may return the string "Netscape" as the value of navigator.


1 Answers

$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());   if($.browser.chrome){   ............  } 

UPDATE:(10x to @Mr. Bacciagalupe)

jQuery has removed $.browser from 1.9 and their latest release.

But you can still use $.browser as a standalone plugin, found here

like image 92
Haim Evgi Avatar answered Oct 15 '22 08:10

Haim Evgi