使用以下代码来防止IE8之前的任何版本的IE加载几个脚本.
问题是脚本仍然在IE7中加载,条件标签(在文档的标题内)实际上被渲染出来并显示在页面上!
<!--[if gte IE 8]-->
<script src="<?php bloginfo('template_url'); ?>/scripts/voter.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/scripts/hover.js" type="text/javascript"></script>
<!--[endif]-->
Run Code Online (Sandbox Code Playgroud) 通过在HTML中使用此技术,曾经有一种很好的方式来判断Web浏览器是否为IE:
<!--[if IE]>
Non-IE browsers ignore this
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
要么
<!--[if !IE]-->
IE ignores this
<!--[endif]-->
Run Code Online (Sandbox Code Playgroud)
但这在IE 10 中不再起作用.
不知道该用什么代替从其他网络浏览器(使用HTML或JavaScript)告诉IE?
PS.我需要能够从非IE网络浏览器告诉任何版本的IE.
html javascript internet-explorer conditional-comments internet-explorer-10
<!--[if IE 6]>
I am using IE6
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
这样可行.
我该怎么做"或" IE7?
html templates conditional-comments internet-explorer-7 internet-explorer-6
基本上,我想知道这段代码是否合适,
<body id="some_id" <!--[if lt IE 7 ]>class="ie6"<![endif]--> >
</body>
Run Code Online (Sandbox Code Playgroud) 我有一段HTML代码,其中包含条件注释:
<!--[if IE]>
<link rel="stylesheet" ...>
<[endif]-->
Run Code Online (Sandbox Code Playgroud)
当包含在页面的HEAD部分中,初始页面呈现时,此代码已经过测试并且可以正常工作.
我想在Ajax响应中使用JavaScript向现有页面引入相同的条件CSS.
我试过了:
var comment = document.createComment("[if IE]>\n<link rel=\"stylesheet\" ...>\n<[endif]");
Wicket.Head.addElement(comment); //this is framework code that just appends the element to the HEAD node of the page. I debugged and verified that it's doing the appendChild(...) call.
Run Code Online (Sandbox Code Playgroud)
上面的代码不会导致样式表在Internet Explorer 7中应用.有没有办法使用JavaScript以Internet Explorer理解的方式引入条件样式?
为了清楚起见,我正在尝试使用JavaScript来创建条件样式,而不是尝试编写具有浏览器条件的JavaScript.
我有一个LESS样式表styles.less,其中包含一些我需要在ie7.css样式表中访问的变量,这些变量是使用条件注释加载的.
鉴于这些是完全独立的样式表,并且考虑到我必须转换ie7.css为ie7.less,我是否可以在两个样式表中提供这些CSS变量?
即我希望能够做如下的事情:
# styles.less, always loaded
@labelwidth: 150px;
# ie7.less, sometimes loaded
label{ margin-left: @labelwidth; }
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用IE条件注释来声明CSS资源:
<h:outputStylesheet name="common.css" library="css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="#{resource['css:ie.css']}" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用.我在生成的HTML输出中看到了这个:
<link type="text/css" rel="stylesheet" href="/context/faces/javax.faces.resource/common.css?ln=css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="/context/faces/javax.faces.resource/ie.css?ln=css"/>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
没有条件注释,它工作正常.我没有使用context参数javax.faces.FACELETS_SKIP_COMMENTS.这是怎么造成的,我该如何解决?
我正在尝试为IE定位一个类.但是,由于样板模板已更改,因此不再有效.
.myclass {
//do something
}
.ie7 .myclass {
///do something
}
Run Code Online (Sandbox Code Playgroud)
这是样板模板的新标题中的内容.
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud) html5 internet-explorer conditional-comments internet-explorer-9 html5boilerplate
我在元素的页面中使用IE条件注释.如果IE <9则获得类"lt-ie9".
然后我使用javascript来检测这个类,如果我找到这个类,那么我将用户重定向到另一个位置.
我的问题是:
"我如何在chrome上测试它?有没有可能测试条件注释是否在chrome中工作?我试图将开发人员工具中的用户代理更改为IE8,但这似乎不起作用."
任何的想法?
PS:我在Mac上,所以像"IETab"这样的扩展不会起作用.
谢谢
internet-explorer google-chrome conditional-comments google-chrome-devtools
我从没想过我是傻瓜,但是......我发现了数百种在html中创建if语句的方法.有人说正确的方法是:
<!--[if IE]>
You're using IE!
<![endif]-->
<![if !IE]>
You're using something else!
<![endif]>
Run Code Online (Sandbox Code Playgroud)
或这个:
<![if !IE]>
//code
<![endif]>
Run Code Online (Sandbox Code Playgroud)
或者看看这个小提琴:http://jsfiddle.net/APFZh/2/
所有这些都不适用于我的电脑.为什么?所有人都说"你必须这样做......"并建议这样的答案,所以他们必须包含工作实例,但......
为什么他们不能在我的浏览器中工作?编写条件语句的正确方法是什么?是小提琴的例子吗?

我试图打开小提琴,即11,而不是FF和改变useragent.史诗.
为什么会这样?我该怎么办?请帮帮我!