Detect IE6 using Javascript / jQuery revisited

I need to define IE6 to get around the lack of position: fixed. I used a simple regex:

var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

This works almost all the time, except for a user whose browser claims to be both IE6 and IE7:

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)

Nice.

I would like to use jquery.support , but it does not seem to support the query about whether the position is available: fixed, So I returned to detecting IE6.

There are various suggested solutions, such as finding maxHeight . But they seem rather random and scare me - if there are exceptions for the regular expression above, how can I be sure that there are no exceptions for maxHeight?

I am thinking about using conditional comments - this way, at least, it will be IE itself, claiming to be IE6, not hacking. Sort of:

<!--[if IE 6]>
<SCRIPT> var isIE6 = true; </SCRIPT>
<![endif]-->

An alternative is f unction, which directly checks if the position is: fixed , but it seems a little heavy.

Any reason my conditional comment approach is not working? Are there any more efficient approaches?

+3
source share
6 answers

Paul Irish $.support position: fixed. , , , .

, :

$.support.positionFixed = (function() { ..... })();

jQuery, , :

if(!$.support.positionFixed) {
  //handle browsers that don't support it
}
+5
<script type="text/javascript">
    if (nothing_works) {
        is_ie6 = true;
    }
</script>

, , , . , , -, , IE6.

, , - IE6.

+6

IE - :

<!--[if IE 6]>
... link IE 6 specific stylesheet or a script...
<![endif]-->

, IE IE6 ( ).

+1

http://api.jquery.com/jQuery.browser/

if ($.browser.msie && parseInt($.browser.version) == 6) {
  // do something
}
0

I say that you should go with conditional comment too. It works well for CSS and JavaScript or whatever you want. It seems to me that this is the best option. But I would not use a variable, as in your example. I would go to the external link ie6.js, which will redefine everything you do in your source code other than ie6. Thus, in your pure code you will not get ie6 junk / variables.

<!--[if IE 6]>
<script type="text/javascript" src="ie6.js"></script>
<![endif]-->
0
source

Source: https://habr.com/ru/post/1758293/


All Articles