Pergunta

I'm wondering if this code works or not:

<!--[if lt IE 8]>
      <script src="/assets/v3/application_ie.js" type="text/javascript"></script>
      <link href="/assets/v3/application_ie.css" media="all" rel="stylesheet" type="text/css" />
    <![endif]-->

I always saw these kind of rules with CSS only, so I'm wondering about javascript here.

Foi útil?

Solução 2

Yes.

In HTML, anything contained within <!-- ... --> is a comment. Anything contained within this comment block will be treated as a comment and not rendered as HTML (and ultimately not displayed on the page). Older versions of IE will parse through HTML comments looking for its square bracket notation and will render the HTML within if a match is made.

Do note, however, that conditional comments like these are no longer supported in modern versions of IE.

Outras dicas

You can have anything you want in a conditional comment.

<!--[if lt IE 8]><p>Update your damn browser!</p><![endif]-->

But you get frowny faces from some people (like me) for having to hax older browsers into working ;) If you need compatibility back there, you should avoid using features that mess up.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top