How do I detect IE 8 with jQuery?

前端 未结 12 1417
一生所求
一生所求 2020-11-30 19:14

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

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 19:35

    You can easily detect which type and version of the browser, using this jquery

    $(document).ready(function()
    {
     if ( $.browser.msie ){
        if($.browser.version == '6.0')
        {   $('html').addClass('ie6');
        }
        else if($.browser.version == '7.0')
        {   $('html').addClass('ie7');
        }
        else if($.browser.version == '8.0')
        {   $('html').addClass('ie8');
        }
        else if($.browser.version == '9.0')
        {   $('html').addClass('ie9');
        }
     }
     else if ( $.browser.webkit )
     { $('html').addClass('webkit');
     }
     else if ( $.browser.mozilla )
     { $('html').addClass('mozilla');
     }
     else if ( $.browser.opera )
     { $('html').addClass('opera');
     }
    });
    

提交回复
热议问题