If IE comments showing up in IE9

2019-09-02 16:04发布

This is what is happening when you visit my site in IE9 - IE9 Error

This is the code that is causing this:

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<link rel="stylesheet" href="stylesheets/ie.css" media="screen" />
<![endif]-->
<!--[if !IE]-->
<link rel="stylesheet" href="stylesheets/sizeable.css" media="screen" />
<!--[endif]-->

<!--[if !IE]-->
<link rel="stylesheet" href="stylesheets/sizeable.css" media="screen" />
<!--[endif]-->

Thoughts?

4条回答
2楼-- · 2019-09-02 16:36

Actually, the "dashes" are correct, but first you must close the conditionals, like so:

<!--[if !IE]> -->
<link rel="stylesheet" href="stylesheets/sizeable.css" media="screen" />
<!-- <![endif]-->

<!--[if !IE]> -->
<link rel="stylesheet" href="stylesheets/sizeable.css" media="screen" />
<!-- <![endif]-->

Not adding the "dashes" will cause no browser to pay attention to these conditionals. Non-IE browsers do not read comments, so the code must be outside the comment for the !IE condition.

查看更多
Juvenile、少年°
3楼-- · 2019-09-02 16:41

EDIT: fixed according to the commenters, thanks. See also the other answers.


Corrected code (second part):

<!--[if !IE]> -->
<link rel="stylesheet" href="stylesheets/sizeable.css" media="screen" />
<!-- <![endif]-->

<!--[if !IE]> -->
<link rel="stylesheet" href="stylesheets/sizeable.css" media="screen" />
<!-- <![endif]-->
查看更多
我命由我不由天
4楼-- · 2019-09-02 16:54

You're closing your comments prematurely. Your conditional comments should open like:

<!--[cond]>

and end like:

<![end]-->

You did the first one right, but because your opening tags end with -->, that closes the comment right there, so the link tag, which is supposed to be part of the comment, isn't, and is interpreted as regular HTML.

Hope that helps!

查看更多
神经病院院长
5楼-- · 2019-09-02 16:59
<!--<![if (IE X)|(IE Y)]--><link href="../css/style.css" rel="stylesheet" type="text/css" media="all" /><!--<![endif]-->

Above conditional comment will work properly For Hiding Comment line you must have to add <!--<! in this format

查看更多
登录 后发表回答