2009-08-05 13 views
5

Ci sono esempi di codice sul IE6 No More website, come questo:Come funziona il codice "IE6 non più"?

<!--[if lt IE 7]> 
<div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative;'> 
    <div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:this.parentNode.parentNode.style.display="none"; return false;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-cornerx.jpg' style='border: none;' alt='Close this notice'/></a></div> 
    <div style='width: 640px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'> 
    <div style='width: 75px; float: left;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-warning.jpg' alt='Warning!'/></div> 
    <div style='width: 275px; float: left; font-family: Arial, sans-serif;'> 
     <div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>You are using an outdated browser</div> 
     <div style='font-size: 12px; margin-top: 6px; line-height: 12px;'>For a better experience using this site, please upgrade to a modern web browser.</div> 
    </div> 
    <div style='width: 75px; float: left;'><a href='http://www.firefox.com' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div> 
    <div style='width: 75px; float: left;'><a href='http://www.browserforthebetter.com/download.html' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-ie8.jpg' style='border: none;' alt='Get Internet Explorer 8'/></a></div> 
    <div style='width: 73px; float: left;'><a href='http://www.apple.com/safari/download/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div> 
    <div style='float: left;'><a href='http://www.google.com/chrome' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div> 
    </div> 
</div> 
<![endif]--> 

Come funziona? Perché questo mostra su IE6 ma non sui nuovi browser?

risposta

12

A causa di questo:

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

Questo è un tag riconosciuta solo dai browser IE-tipo, che in inglese dice: "Se versione del browser è inferiore a IE7, mostrare questo".

+1

Ah, duh. L'ho letto come se quelle due righe fossero commenti, e il codice tra non era parte del commento. Grazie :) –

2

Conditional Comments

... è una caratteristica specifica di IE che consente di indirizzare le diverse versioni dei loro browser.

1

Questo codice "chiede" al browser quale versione è (utilizzando il browser user agent). Se è "minore di" (lt) IE 7 (quindi IE 6, IE 5, IE 4, IE 3, IE 2, IE 1), visualizza l'HTML tra i due tag.