如果浏览器是ie9,则执行某些javascript [英] Execute certain javascript if browser lt ie9

查看:100
本文介绍了如果浏览器是ie9,则执行某些javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果浏览器低于IE9,我想在jQuery中执行某些代码。是的,我已经知道了

I want to execute a certain code in jQuery if the browser is lower than IE9. And yes, i already know about

<!--[if ... IE ]> <![endif]-->

但我想要的是在scipt标签和jQuery document.ready中检查这个条件

But what i want is to check this condition within the scipt tag and with jQuery document.ready

<script>
    $(document).ready(function(){
        //code to check if lt ie9 
    });
</script>


推荐答案

您可以定位较旧的Internet Explorer版本(< = 9)通过< html> 元素上的类......

You can target older Internet Explorer versions (<= 9) through classes on the <html> element...

<!--[if lt IE 7]>  <html class="ie ie6 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 7]>     <html class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]>     <html class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]>     <html class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]>  <html> <![endif]-->
<!--[if !IE]><!--> <html>             <!--<![endif]-->

...然后检查< html> 具有类 .lt9 .lt8 - 您要定位的Internet Explorer的任何版本:

... and then check if <html> has the class .lt9 or .lt8 — whatever version of Internet Explorer you are targeting:

if($('html').hasClass('lte9')) { /* LTE IE9 */ }

但是,我建议使用 Modernizr 功能检测而不是检查特定浏览器。

However, I would suggest using Modernizr feature detection instead of checking for a specific browser.

这篇关于如果浏览器是ie9,则执行某些javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆