1

I am trying to establish how to detect the IE browser in jQuery 1.3.X - now before you all write "its deprecated in 1.3.x!" - I know this. I have this code

if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
  alert ("This is less than IE7");
} else {
  alert ("This is greater than IE7");
}

When running it in IE8 - IE6 (quirks), IE7 and IE8 all return "less than IE7". Can anyone help me determine this correctly using jquery ? (please note: using jquery)

Edit: I am trying to basically change the position element in IE6 to "absolute" and use "fixed" for IE7 and IE8. Not sure how to do this without detecting browser?

Edit2: Seems something like this might work?

   if ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined)) {
        alert ("This is not IE6");
       } else {
        alert ("This is greater than IE6"); 
       }
  • 2
    What's your ultimate goal here? The whole point of jQuery is to abstract this sort of thing. It's better to check for a feature than for a particular browser. – Draemon Jul 26 '09 at 12:48
  • hey draemon - i am trying to basically change the position element in IE6 to "absolute" and use "fixed" for IE7 and IE8. Not sure how to do this without detecting browser? –  Jul 26 '09 at 12:50
  • I provided a method that relies on object detection. – meder omuraliev Jul 26 '09 at 12:51
  • I'm about to edit your code to put a closing brace before the else block. This wasn't the issue was it? – scunliffe Jul 26 '09 at 12:58
  • hey thanks scunliffe. nah, sorry just missed pasting apologies. it doesnt work in IE anymore this code - so just hoping someone can tell me how to resolve this ? :) –  Jul 26 '09 at 13:00
  • You aren't doing anything like running multiple versions of Internet Explorer on the same OS, are you? – Joe Chung Jul 26 '09 at 13:08
  • hey chung - nah. just using IE8 to test and when I rotate through the Developer tools quirks, iE7 and ie8 - always get "less than ie7" ? –  Jul 26 '09 at 13:13
  • This CSS would give IE6 the specific property that you were looking for: * html #thing {position: absolute;} #thing {position: fixed;} If this is what you're looking for, you may want to re-word your question and post this as an answer. – Jacob Hume Dec 03 '09 at 17:04
  • Edit2's `if(window.XMLHttpRequest == undefined)...` gives a false-positive for IE 8 users that turn off “Enable native XMLHTTP support” option in their advanced settings. – foson Oct 24 '11 at 14:36

3 Answers3

2

you can always do this sort of thing with html or css...why do it with jquery?

codedude
  • 6,244
  • 14
  • 63
  • 99
0

the method in the update #2 above, i.e. checking for the XMLHttpRequest member on the window, can fail in cases where some other library has polyfilled support. You're best bet is going to be to use conditional comments, this page has an excellent explanation.

hope that helps! cheers.

keeganwatkins
  • 3,636
  • 1
  • 14
  • 12
0
if ($.browser.msie  && parseInt($.browser.version, 10) < 7) {
  alert('This is less than IE7');  // just alerting what you said in question
} else {
  alert('Better than IE6'); // What if I'm not IE?
}
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236