Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

internet explorer 8 - Html detect IE8 and lower or any other browser

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...