Howto detect Chrome Browser with jQuery

By 22. Februar 2013 general No Comments

The official site of jQuery.browser (http://api.jquery.com/jQuery.browser) doesn’t show how to detect if the user is using the Chrome browser.

$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 

This saves the user Agent to $.browser.chrome… but the userAgent can be changed easily.
Here is a more robust version which uses a global variable:

$.browser.chrome = (typeof window.chrome === "object");

If the browser is chrome the variable $.browser.chrome is set to true and can be checked like this:

if($.browser.chrome){
  ...
}