标签: conditional-comments

/*@ cc_on和IE6检测

在研究IE的JavaScript条件评论时,我偶然发现了@cc_on.这似乎有效.但是,条件注释的维基百科条目为更强大的IE检测提供了以下代码,特别是IE6:

/*@cc_on
    @if (@_jscript_version > 5.7)
    document.write("You are using IE8+");

    @elif (@_jscript_version == 5.7 && window.XMLHttpRequest)
    document.write("You are using IE7");

    @elif (@_jscript_version == 5.6 || (@_jscript_version == 5.7 && !window.XMLHttpRequest))
    document.write("You are using IE6");

    @elif (@_jscript_version == 5.5)
    document.write("You are using IE5.5");

    @else
    document.write("You are using IE5 or older");

@end

@*/
Run Code Online (Sandbox Code Playgroud)

问题是,我得到一个"预期的常量"javascript错误!window.XMLHttpRequest.

很明显,维基百科需要一些帮助,我需要让它发挥作用.谁能帮我吗?

javascript internet-explorer conditional-comments internet-explorer-6 browser-feature-detection

5
推荐指数
1
解决办法
5868
查看次数

JSF 2.1和IE条件评论

我注意到在JSF 2.1中.*我的IE条件注释不再有效.HTML实体正在替换各种字符并使注释语法无效.BalusC 在另一个使用h:outputText 的问题中指出了问题的解决方案.我的问题是我希望我的条件评论位于我的页面顶部,围绕第一个元素.这意味着我不能使用h:outputText,因为我还没有定义它的命名空间.无论如何,我相信这是正确的.这是一个代码示例.

现在大多数JSF页面都会以类似于HTML5 Boilerplate语法的模板开始:

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7 my-application" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8 my-application" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9 my-application" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js my-application" xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" lang="en"><!--<![endif]-->
<h:head>
  <meta charset="utf-8" />
  ...
Run Code Online (Sandbox Code Playgroud)

有了BalusC提到的解决方案,我想<h:outputText />在第2行但是h命名空间还没有定义.这是我可以使用的元素,我可以附加各种命名空间但不会影响我的最终HTML吗?我有什么其他想法可以解决这个问题吗?

李,

jsf conditional-comments jsf-2

5
推荐指数
1
解决办法
3016
查看次数

为样式表创建有效的条件注释,而不会出现"伪造注释"验证器错误

我的头标记中有以下内容:

<link rel="stylesheet" href="Scripts/styleMain.css" media="all" type="text/css" />
<![if gte IE 9]><!-->
<link rel="stylesheet" href="Scripts/styleMob.css" media="screen and (max-width:500px)" type="text/css" />
<link rel="stylesheet" href="Scripts/styleDes.css" media="screen and (min-width:501px)" type="text/css" />
<!--<![endif]-->
<!--[if lt IE 9]>
<link rel="stylesheet" href="styleDes.css" type="text/css" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

问题是,第二行被认为是虚假评论,而同一行上的第二个标记被认为是评论的过早结束.

在同一行上添加额外的标签,并在第一个endif上给我两个假的评论错误.

有什么方法可以让我的样式表有条件,并让他们验证?或者我注定要在我的OCD编码中使用无效的代码?

html validation conditional-comments

5
推荐指数
1
解决办法
3508
查看次数

IE10正在阅读IE8条件评论

如果您使用的是不受支持的浏览器,我有一个显示警告框的网页,IE <= 8.这在IE 8及以下版本中运行良好,但是今天我在IE 10中测试它似乎也读取了这个条件.它显示警告框时不应该.我尝试了很多东西,但我不知道可能是什么问题.以下是一些代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="chrome=1"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
 ...
</head>
<!--[if lte IE 8]>
    <div style="position:absolute;bottom:0px;left:0px;background-color:orange;color:white;z-index:1000;width:250px;text-align:center;">This content is best viewed in Chrome, Firefox or any other Modern Browser. <br/><strong>Please Upgrade.  </strong></div>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

html meta internet-explorer conditional-comments internet-explorer-10

5
推荐指数
1
解决办法
1835
查看次数

IE与Sass和Bourbon的条件注释

我想为不同的浏览器提供不同的字体(请参阅此问题)。

用Sass / Bourbon可以做到这一点吗?

这是我到目前为止的内容:

<!--[if IE]> -->
@include font-face("myicons", "myicons", $weight: normal, $style: normal,
                   $asset-pipeline: false);
<![endif]-->
<!--[if !IE]> -->
@include font-face("myicons", "myicons", $weight: normal, $style: normal,
                   $asset-pipeline: true);
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

css sass conditional-comments bourbon

5
推荐指数
1
解决办法
5353
查看次数

IE条件评论工作但标签可见?

我有很棒的HTML5 javascript shim链接到我的<head>.

除了它在页面顶部显示标签,它工作正常,即:

<!--[if lt IE9]> <![endif]-->

当我查看源代码时,它看起来绝对精致和花花公子.我完全不知道发生了什么!

internet-explorer conditional-comments

4
推荐指数
1
解决办法
771
查看次数

如果<noscript> OR <! - [if lte IE 7]>满足条件注释,而不重复内容,则显示内容?

我正在开发一个不支持IE6或IE7的Javascript驱动的交互式工具.

如果有人使用旧的IE,或者使用禁用Javascript的浏览器,我们会给他们一些简单的静态内容作为后备:普通图像和文本.

可以通过复制静态内容,<noscript>块中的一个副本和条件注释中的一个副本来做到这一点,像这样......

<!--[if lte IE 7]>
<div id="some-id">
<p> Some content </p>
<img src="url.com" alt="Screenshot of awesome tool" title="This is what you're missing" />
<p> Some more content </p>
<div id="some-more"> ... etc ... </div>
</div>
<![endif]-->

<noscript><![if !(lte IE 7)]> 
<div id="some-id">
<p> Some content </p>
<img src="url.com" alt="Screenshot of awesome tool" title="This is what you're missing" />
<p> Some more content </p>
<div id="some-more"> ... etc ... </div>
</div>
<![endif]></noscript>
Run Code Online (Sandbox Code Playgroud)

...但如果可能的话,最好避免重复这样的内容.没有不必要的重量,更容易更新,没有任何搜索引擎机器人将隐藏的重复内容解释为关键字垃圾邮件等的风险.此外,避免重复只是一个普遍的好习惯.

(另外,我们可能会失去可怕<![if …

html javascript internet-explorer noscript conditional-comments

4
推荐指数
1
解决办法
4327
查看次数

不要在IE8及以下版本中加载脚本?

这个问题必须重复,但我在这里找不到明确的答案.

如果浏览器是IE8或更低版本,如何告诉浏览器不加载脚本?

我知道针对IE9及以上的目标:

<!--[if gte IE 8]>
 According to the conditional comment this is IE 8 or higher<br />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

但是然后脚本不会加载到非IE浏览器中.

如果不是IE,或者如果IE和IE8以上,我该如何说"加载脚本"?

html browser internet-explorer conditional-comments

4
推荐指数
1
解决办法
5182
查看次数

我可以在html文档的底部放置条件注释吗?(在体内)还是应该在头部?

<script>if(BrowserDetect.browser=="safari"){document.write('<link rel="stylesheet" href="css/safari.css" type="text/css" media="all" />')}</script>

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

我可以在html文档的底部放置条件注释吗?(在体内)还是应该在头部?

放置在底部的那些在页面速度方面是否更好?

html javascript html5 conditional-comments

4
推荐指数
1
解决办法
548
查看次数

如何向hamlet模板添加条件注释?

如何向莎士比亚模板添加条件注释(或任何类型的Html注释)?

如果我加

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

到我的hamlet模板只生成一个空行.

html haskell conditional-comments yesod hamlet

4
推荐指数
1
解决办法
179
查看次数