How to write one IE conditional comment to target all IE versions at once?

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

I want to use a JavaScript only for all IE version 6,7 and 8.

回答1:

Nested conditions (WRONG):

<!--[if lte IE 8]>   <!--[if gte IE 6]>   <!-- your stuff here -->  <![endif]-->  <![endif]--> 

EDIT: As Martha highlighted, nested condition don't work, use " & ":

<!--[if (lte IE 8) & (gte IE 6)]>    <!-- your stuff here -->   <![endif]--> 

Other examples from MSDN:

<!--[if IE]><p>You are using Internet Explorer.</p><![endif]--> <![if !IE]><p>You are not using Internet Explorer.</p><![endif]>  <!--[if IE 7]><p>Welcome to Internet Explorer 7!</p><![endif]--> <!--[if !(IE 7)]><p>You are not using version 7.</p><![endif]-->  <!--[if gte IE 7]><p>You are using IE 7 or greater.</p><![endif]--> <!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]--> <!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]--> <!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->  <!--[if true]>You are using an <em>uplevel</em> browser.<![endif]--> <![if false]>You are using a <em>downlevel</em> browser.<![endif]>  <!--[if true]><![if IE 7]><p>This nested comment is displayed in IE 7.</p><![endif]><![endif]--> 


回答2:

You can target conditional comments at Internet Explorer regardless of version:

<!--[if IE]> IE stuff goes here <![end if]--> 

See http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx



回答3:

You could do this to prevent it from applying to future versions of IE

<!--[if lt IE 9]> Content for IE less than version 9 goes here <![endif]--> 


回答4:

This one blew me away, but check it out:

var IE = /*@cc_on!@*/false; 

Source



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!