1

I have below lines of code in my jsp page.

<!--[if lt IE 7]><html lang="en" class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml"> <![endif]-->
<!--[if IE 7]><html lang="en" class="no-js lt-ie10 lt-ie9 lt-ie8" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml"> <![endif]-->
<!--[if IE 8]><html lang="en" class="no-js lt-ie10 lt-ie9" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml"> <![endif]-->
<!--[if IE 9]><html lang="en" class="no-js lt-ie10" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml"> <![endif]-->
<!--[if gt IE 9]><!--><html lang="en" class="no-js" xmlns="http://www.w3.org/1999/html" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml"> <!--<![endif]-->

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html>

  //some code

</html>

The code works fine in IE7 and all the browsers. But when i use IE9 it gives below the error in IE console and the page is not rendered.

LOG : Incompatible IE Document Mode

Please help me.

Thanks!

4

1 回答 1

1

doctype 必须是 HTML 文件的第一行。您还打开了 HTML 标记两次,一次在每个 IE 条件中,然后再次在下面。

如果您计划支持 IE 以外的浏览器,那么使用条件语句包装 HTML 标记并不是一个好的解决方案,因为无法为其他浏览器定义 HTML 标记,因为它们会忽略条件注释。

一种解决方案是将所有类添加到 HTML 标记中,然后根据 IE 的版本有条件地导入 css 文件。这些文件会根据浏览器定义你需要的类;例如ltIE7.css将定义 .lt-ie7 类,ltIE8.css将定义 .lt-ie8 类等。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7" lang="en" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
        <!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="ltIE7.css"/><![endif]-->
        <!--[if lt IE 8]><link rel="stylesheet" type="text/css" href="ltIE8.css"/><![endif]-->
        <!--[if lt IE 9]><link rel="stylesheet" type="text/css" href="ltIE9.css"/><![endif]-->
        <!--[if lt IE 10]><link rel="stylesheet" type="text/css" href="ltIE10.css"/><![endif]-->
    </head>
    <body>
        ...
    </body>
</html>

或者,如果您不想使用外部 CSS 文件,您可以使用以下条件注释内联定义类head

<style type="text/css">
    <!--[if lt IE 7]>
        .lt-ie7 {...}
    <![endif]-->
    <!--[if lt IE 8]>
        .lt-ie8 {...}
    <![endif]-->
    <!--[if lt IE 9]>
        .lt-ie9 {...}
    <![endif]-->
    <!--[if lt IE 10]>
        .lt-ie10 {...}
    <![endif]-->
</style>
于 2013-08-20T11:35:44.287 回答