如何针对某些情况(如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
我遇到了麻烦
<!--[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)
那没用.基本上我正试图让这个页面工作 …
我正在使用新的Internet Explorer 11开发人员工具将文档模式切换为"8",但条件注释仍然被忽略,即它们未被正确解析并且表现得像普通注释.因此,浏览器不会请求/加载条件注释中的任何引用文件.
为什么会这样?这是一个错误吗?
如果您认为这确实是一个需要修复的错误,请进入并说您也可以在针对此问题报告的Microsoft错误报告中重现此问题:
通过F12 Developer模拟文档模式时,条件注释不起作用工具.
更新:已报告此问题已在上述错误报告中修复.
browser internet-explorer conditional-comments internet-explorer-11 ie11-developer-tools
为了检测IE,大多数Javascript库都做了各种各样的技巧.
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
我知道您可以在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?
对于Internet Explorer 8(IE8),我想使用以下CSS:
color : green;
Run Code Online (Sandbox Code Playgroud)
我想应用一个只影响IE8的黑客,而不是IE9,IE6和7.
我以为我记得读过某个IE9 不会支持他们的地方,但现在搜索后我找不到任何迹象表明这是真的.
对于微软是否会支持IE9中的条件评论,是否有人知道一个明确的声明?
html internet-explorer conditional-comments internet-explorer-9
我不想为IE 6/7使用几个javascript插件.但我想将它们用于所有其他浏览器.
我该怎么做?有什么办法可以吗?
这是我在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]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Faces Servlet服务后源已更改的任何原因?
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)