Почему таблица стилей загружается, когда Conditional Comment заявляет, что ее следует игнорировать? - PullRequest
1 голос
/ 28 апреля 2009

Я думал, что условные комментарии будут указывать браузеру игнорировать контент, если условие не выполняется?!

Например, я хочу включить таблицу стилей, только если IE6 является браузером. Следующее находится в элементе страницы.

<!--[if IE 6]>
  <link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="~/css/IE6.css" runat="server" />
<![endif]-->

или

<!--[if IE 6]>
  <link rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->

Почему IE7, IE8 и FF3 все загружают эту таблицу стилей?!

ПРИМЕЧАНИЕ. Изменение условия на [if lte IE 6] не имеет значения! (

ОСНОВНОЕ ОБНОВЛЕНИЕ

Я идиот ... Я только что заметил, что я сделал не так! Пример, который я привел, был немного изменен. Путь к css-файлу в разделе App_Themes! Конечно, CSS всегда был загружен !!!

1 Ответ

2 голосов
/ 28 апреля 2009

Попробуйте:

<!--[if lte IE 6]>
   <link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->

Это загрузит таблицу стилей только для IE6 или более ранних версий. Вот тестовый скрипт, который вы можете использовать, он выведет, какую версию IE вы используете:

<p><!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->
<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]-->
<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]-->
<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]-->
<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]-->
<!--[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]-->
<!--[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]-->
</p>

Вы не должны видеть текст в Firefox с этим тестовым кодом.

...