views:

440

answers:

5

I need to detect not only the browser type but version as well using jquery. mostly I need to find out if it is ie 8 or not. thank you

I am not sure if i am doing it correctly

if I do :

if (jQuery.browser.version >= 8.0) { dosomething}

I am not sure it will work for version 8.123.45.6 or will it?

+2  A: 

You can use jQuery browser method. Docs.

Teja Kantamneni
+3  A: 

It is documented here. Check for Internet Explorer with $.browser.msie and then check its version with jQuery.browser.version.

AndiDog
if I do :if (jQuery.browser.version >= 8.0) { dosomething}I am not sure it will work for version 8.123.45.6 or will it?
salmane
It is a string, so you should do `if(jQuery.browser.version.substring(0, 2) == "8.") { ... }`. That way it will work with all versions of IE8.
AndiDog
+2  A: 

Don't forget that you can also use HTML to detect IE8.

<!--[if IE 8]>
<script type="text/javascript">
    ie = 8;
</script>
<![endif]-->

Having that before all you scripts will let you just check the "ie" variable or whatever.

TheBuzzSaw
A: 

You should also look at jQuery.support. Feature detection is a lot more reliable than browser detection for coding your functionality (unless you are just trying to log browser versions).

jkyle
+1  A: 

document.documentMode is undefined if the browser is not IE8,

it returns 8 for standards mode and 7 for 'compatable to IE7'

If it is running as IE7 there are a lot of css and dom features that won't be supported.

kennebec