标签: conditional-comments

如何针对某些情况(如Internet Explorer特定的CSS或特定于Internet Explorer的JavaScript代码)仅定位Internet Explorer 10?

如何针对某些情况(如Internet Explorer特定的CSS或特定于Internet Explorer的JavaScript代码)仅定位Internet Explorer 10?

我试过这个,但它不起作用:

<!--[if IE 10]>    <html class="no-js ie10" lang="en"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

Internet Explorer 10忽略条件注释并使用<html lang="en" class="no-js">而不是<html class="no-js ie10" lang="en">.

html javascript css conditional-comments internet-explorer-10

159
推荐指数
10
解决办法
16万
查看次数

<! - [if!IE]>不工作

我遇到了麻烦

<!--[if !IE]>
Run Code Online (Sandbox Code Playgroud)

上班.我想知道是不是因为我的文件中有这个

<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

当我添加

<!--[if !IE]><!-->
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css" />
<!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

由于某种原因,我的标题不起作用.但是,如果我添加

<!--[if !IE]><!-->
    <style>
        All my css in here
    </style>
    <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

到实际的html页面(在标题中)它的工作原理.有什么建议?干杯

更新我的问题

好吧,当我删除时, <!-->我只检查了IE工作,但现在回到FF中,no-ie.css也已应用于FF.所以我添加回来<!-->并删除了/(并将其添加到主模板中,因此cms不会将其添加回来)并且所有都在FF中工作但现在样式表正在应用于IE!所以我试过了

<!--[if IE]>
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css">
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

<!--[if !IE]> -->
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css">
<!-- <![endif]-->
Run Code Online (Sandbox Code Playgroud)

那没用.基本上我正试图让这个页面工作 …

html internet-explorer conditional-comments

137
推荐指数
10
解决办法
33万
查看次数

为什么Internet Explorer 11即使在模拟Internet Explorer 8文档模式时也不尊重条件注释?

我正在使用新的Internet Explorer 11开发人员工具将文档模式切换为"8",但条件注释仍然被忽略,即它们未被正确解析并且表现得像普通注释.因此,浏览器不会请求/加载条件注释中的任何引用文件.

为什么会这样?这是一个错误吗?

如果您认为这确实是一个需要修复的错误,请进入并说您也可以在针对此问题报告的Microsoft错误报告中重现此问题:
通过F12 Developer模拟文档模式时,条件注释不起作用工具.

更新:已报告此问题已在上述错误报告中修复.

browser internet-explorer conditional-comments internet-explorer-11 ie11-developer-tools

111
推荐指数
5
解决办法
4万
查看次数

Javascript IE检测,为什么不使用简单的条件注释?

为了检测IE,大多数Javascript库都做了各种各样的技巧.

  • jQuery似乎在页面的DOM中添加了一个临时对象来检测某些功能,
  • YUI2对其YAHOO.env.ua = function()(文件yahoo.js)中的用户代理进行正则表达式

在阅读了这个答案之后,我想到了这是真的,为了在Javascript中简单地检测IE,我们可以简单地添加到我们的页面:

<!--[if IE]><script type="text/javascript">window['isIE'] = true;</script><![endif]-->

<script type="text/javascript" src="all-your-other-scripts-here.js"></script>
Run Code Online (Sandbox Code Playgroud)

现在,window.isIE为我们所有的Javascript代码设置变量,只需执行以下操作:

if(window.isIE)
   ...
Run Code Online (Sandbox Code Playgroud)

除了这可能导致痛苦,因为它必须在所有页面中添加之外,是否存在我可能不知道的任何问题/考虑因素?


仅供参考:我知道最好使用对象检测而不是浏览器检测,但有些情况下您仍然需要使用浏览器检测.

javascript internet-explorer browser-detection conditional-comments

47
推荐指数
5
解决办法
7万
查看次数

在样式表中使用IE条件注释

我知道您可以在HTML中使用IE条件注释:

<!--[if IE]>
  <link href="ieOnlyStylesheet.css" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

但是,如果我想在样式表中仅定位IE,为html中的特定元素设置css规则,该怎么办?例如,您可以在css文件中使用此Chrome/Safari hack 作为css代码...

@media screen and (-webkit-min-device-pixel-ratio:0) {
    .myClass{
        background: #fff;
        background:rgba(255,0,255,0.7);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是使用CSS样式表中的IE hack如下:

 <!--[if IE]>
      .myClass{
        background: #fff;
        background:rgba(255,0,255,0.7);
    }
 <![endif]-->
Run Code Online (Sandbox Code Playgroud)

不起作用.我在样式表中使用什么来仅针对IE?

css conditional-comments

31
推荐指数
3
解决办法
9万
查看次数

有没有IE8只有css黑客?

对于Internet Explorer 8(IE8),我想使用以下CSS:

color : green;
Run Code Online (Sandbox Code Playgroud)

我想应用一个只影响IE8的黑客,而不是IE9,IE6和7.

css conditional-comments internet-explorer-8

27
推荐指数
4
解决办法
10万
查看次数

IE9会支持条件评论吗?

我以为我记得读过某个IE9 不会支持他们的地方,但现在搜索后我找不到任何迹象表明这是真的.

对于微软是否会支持IE9中的条件评论,是否有人知道一个明确的声明?

html internet-explorer conditional-comments internet-explorer-9

23
推荐指数
3
解决办法
1万
查看次数

如何为非IE浏览器编写条件注释?

我不想为IE 6/7使用几个javascript插件.但我想将它们用于所有其他浏览器.

我该怎么做?有什么办法可以吗?

html conditional-comments internet-explorer-7

17
推荐指数
2
解决办法
6781
查看次数

如何在JSF中使用Internet Explorer条件注释?

这是我在Eclipse中的源代码文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>

<body>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我在IE9中查看它时,它呈现文本:

<!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
Run Code Online (Sandbox Code Playgroud)

如果我查看来源它说:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--[if lt IE 9]&gt;

      &lt;script src=&quot;http://html5shim.googlecode.com/svn/trunk/html5.js&quot;&gt;&lt;/script&gt;

    &lt;![endif]-->
</head>

<body>


</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Faces Servlet服务后源已更改的任何原因?

jsf internet-explorer facelets conditional-comments jsf-2

17
推荐指数
2
解决办法
6421
查看次数

在`[if lt IE 9]`中`lt`的含义是什么?

lt以下脚本的含义是什么?

<!--[if lt IE 9]>
  <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html5.min.js">
  </script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

html css conditional-comments

16
推荐指数
2
解决办法
2万
查看次数