为什么Chrome会忽略IE条件标记?

时间:2014-04-04 00:59:34

标签: wordpress twitter-bootstrap internet-explorer conditional

我正在使用自定义bootstrap wordpress主题。

我的头是根据Bootstrap建议创建的

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php // Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. ?>
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<?php wp_head(); ?>
</head>

我可能误解了IE condtional标签的重要性,但我预计IE黑客代码只能在IE中加载,但所有这些脚本都存在于Chrome中。

我是否误用了这个标签?是否有另一种推荐的方法来确保这些脚本仅为比版本9更轻的IE浏览器加载?

我更喜欢让我的网页尽可能轻,所以我不想让不必要的代码加载只是为了安抚那些仍然使用ie8及以下的傻瓜。

1 个答案:

答案 0 :(得分:5)

-->结束评论。那么,这个评论的结尾:

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->

也是对Chrome渲染引擎发表评论的部分的结尾。

解决方案很简单:只需将注释标签移到IE条件之外。

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->