My site only works on chrome 11 how can I check if the user runs this version?
-
1It's pointless trying this, by the time you've got the details worked out they'll be running version 12! – David Heffernan Mar 24 '11 at 15:09
4 Answers
You can do browser detection like already answered by others, but feature detection might be a better road to take.
You can get some inspiration by reading this post: Browser detection versus feature detection
Also read about browser detection pitfalls here: https://developer.mozilla.org/en/Browser_Detection_and_Cross_Browser_Support
Also you can read more about feature detection here: http://michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
And finally you can use the modernizr library here: http://www.modernizr.com/

- 1
- 1

- 25,743
- 8
- 56
- 68
-
+1, version == X is just asking for trouble! (And a blast from the past) – Flexo Mar 24 '11 at 15:06
-
1+1. Feature checking is the way to go if at all possible, since then your code will work seamlessly on other browsers once they support the features you need. – Brian Campbell Mar 24 '11 at 15:08
var running_chrome_11 = navigator.userAgent.toLowerCase().indexOf('chrome/11') > -1;
This will either be true or false.
However as suggested, it is highy recommend to check against the current features, rather than the version number. An example might be:
if(window.localStorage){ // you can run local storage }

- 63,433
- 20
- 141
- 111
-
5This won't match Chrome 12 (which presumably will run the same code that Chrome 11 did), but it will match Chrome 110. It's probably better to parse out the entire number, and compare it numerically, not with a string check. – Brian Campbell Mar 24 '11 at 15:05
using jquery.
if ($.browser.chrome && $.browser.version == 11)

- 516
- 2
- 7
-
the question said "only works on chrome 11", but if you'd like, you can use >= 11 for the browser version. – rucsi Mar 24 '11 at 15:44
-
chrome numbers are usually something like 27.002.3525.34.. so you might need to parse the first one out of there. something like that: if($.browser.chrome && parseInt($.browser.version.split('.')[0]) >= 25){//do magic here} note that this $.browser thing is not in default jquery package so you need to add some plugin for that. here's more information: http://api.jquery.com/jQuery.browser/ – dsomnus Jul 08 '13 at 19:54
parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 11

- 322,767
- 57
- 360
- 340
-
parseInt(navigator.userAgent.match(/Chrom(e|ium|eframe)\/([0-9]+)\./i)[2]) for chrome frame detection too – Mark Nadig Aug 03 '12 at 18:02
-
When not matching "Chrome" substring, this code generates exception in all non-Chrome browsers. Like this: null[2]. – Dan May 07 '15 at 22:11