Html检测IE8和更低或任何其他浏览器

时间:2014-07-30 19:42:13

标签: html internet-explorer-8

使用HTML评论,我正在尝试执行以下操作 -

<!-- [if lte IE 8] -->  //if browser is IE8 or less display the following
    <div>IE8</div>    
<!-- [endif] -->

<!-- [if ANY OTHER BROSWER] -->  //any other browser do this
    <div>Any other browser</div>   
<!-- [endif] -->

我似乎无法找到有效的组合?怎么办呢?

2 个答案:

答案 0 :(得分:1)

Reference

<!--[if IE 8]>
    According to the conditional comment this is IE 8<br />
<![endif]-->

<!--[if lt IE 9]>
    According to the conditional comment this is IE lower than 9<br />
<![endif]-->

<!--[if gt IE 7]>
    According to the conditional comment this is IE greater than 7<br />
<![endif]-->

例如,

<html>
    <head>
        <link rel="stylesheet" href="my-styles.css">
        <!--[if IE 8]>
            <link rel="stylesheet" href="my-ie8-only-styles.css">
        <![endif]-->
    </head>
    <body>
        <p>Hello World!</p>
    </body>
</html>

或者你可以用它来渲染某些html标记...

....
<!--[if IE 8]>
    <div id="ie8Only">IE8 Only</div>
<![endif]-->
....

答案 1 :(得分:1)

我知道这有点老问题,但这是我的解决方案

    <!--[if lt IE 9]><!-->
        <script src="~/Scripts/jquery-1.10.2.min.js"></script>
        <script src="~/Scripts/html5shiv.js"></script>
    <!--<![endif]-->
    <!--[if (gte IE 9) | (!IE)]><!-->
    <script src="~/Scripts/jquery-2.1.4.min.js"></script>
    <!--<![endif]-->