Detect IE6 with Jquery

2019-08-01 22:27发布

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"); 
       }

3条回答
劳资没心,怎么记你
2楼-- · 2019-08-01 22:38
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?
}
查看更多
甜甜的少女心
3楼-- · 2019-08-01 22:42

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

查看更多
乱世女痞
4楼-- · 2019-08-01 22:54

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.

查看更多
登录 后发表回答