Code Snippet: Detect Google Chrome w/JavaScript

With Chrome entering the browser market, you may find a need in the not too distant future to code some exceptions for it. In case that day comes, here's a quick snippet of JavaScript for detecting if your users are Chromed out:

You can detect Chrome using the following:
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

Chrome's full user agent:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13

Hi Mark,

Thanks a lot for the snippet.

[...] Guru Prasath wrote an interesting post today onHere’s a quick excerptWith Chrome entering the browser market, you may find a need in the not too distant future to code some exceptions for it. In case that day comes, here’s a quick snippet of JavaScript for detecting if your users are Chromed out: … [...]

[...] voilà, merci Ajaxonomy [...]

/\bchrome\b/i.test(navigator.userAgent)
or
~navigator.userAgent.toLowerCase().indexOf('chrome')

both shorter than
navigator.userAgent.toLowerCase().indexOf('chrome')>-1

The browser indeed is very promising and Firefox / Microsoft IE have to pull up their socks because the real competition is about to begin :D

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <div> <blockquote> <object> <embed> <img> <param>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.