Html detect IE8 and lower or any other browser

2019-08-19 04:57发布

With HTML comments, I am trying to do something like the following -

<!-- [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] -->

I can't seem to find a combination that works? How can this be done?

2条回答
在下西门庆
2楼-- · 2019-08-19 05:13

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]-->

For example,

<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>

Or you could use it to only render certain html markup...

....
<!--[if IE 8]>
    <div id="ie8Only">IE8 Only</div>
<![endif]-->
....
查看更多
够拽才男人
3楼-- · 2019-08-19 05:21

I know it's a bit old question, but here's my solution

    <!--[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]-->
查看更多
登录 后发表回答