Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect IE 8 with jQuery?

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.

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?

Edit: Note that JQuery 2+ has dropped support for IE8 and below, and therefore can no longer be used to detect IE8. If using a current version of JQuery, it is necessary to use a Non-JQuery solution.

like image 370
salmane Avatar asked Feb 04 '10 18:02

salmane


People also ask

Does jQuery work in IE8?

1 Answer. Show activity on this post. IE8 support was dropped in jQuery 2. x, so you will want any version beginning with 1 that satisfies your plugin's version dependencies.

How do I know if jQuery is installed in Terminal?

You can test if jQuery is loaded by opening your javascript console (in Chrome: Settings > More tools > Javascript console). Where the little blue arrow appears type: if(jQuery) alert('jQuery is loaded'); Press enter.


1 Answers

I think the best way would be this:

From HTML5 boilerplate:

<!--[if lt IE 7]> <html lang="en-us" class="no-js ie6 oldie"> <![endif]--> <!--[if IE 7]>    <html lang="en-us" class="no-js ie7 oldie"> <![endif]--> <!--[if IE 8]>    <html lang="en-us" class="no-js ie8 oldie"> <![endif]--> <!--[if gt IE 8]><!--> <html lang="en-us" class="no-js"> <!--<![endif]--> 

in JS:

if( $("html").hasClass("ie8") ) { /* do your things */ }; 

especially since $.browser has been removed from jQuery 1.9+.

like image 155
meo Avatar answered Sep 30 '22 14:09

meo