您的位置:首页 > 理论基础 > 计算机网络

<meta http-equiv="X-UA-Compatible" content="IE=edge">

2016-08-13 11:08 501 查看
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title>Starter Template for Bootstrap</title>

<!-- Bootstrap core CSS -->
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="starter-template.css" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="../../assets/js/ie-emulation-modes-warning.js"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>

<div class="container">

<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>

</div><!-- /.container -->

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>


第五行代码之前没见过,看不懂这行代码的意思,于是网上查了一下,基本看懂了。

 

另一篇博客

1,X-UA-Compatible是神马? 
文档:https://www.modern.ie/en-us/performance/how-to-use-x-ua-compatible 

X-UA-Compatible是IE8的一个专有<meta>属性,它告诉IE8采用何种IE版本去渲染网页,在html的<head>标签中使用。可以在微软官方文档获取更多介绍。 

为什么要用X-UA-Compatible? 

在IE8刚推出的时候,很多网页由于重构的问题,无法适应较高级的浏览器,所以使用X-UA-Compatible标签强制IE8采用低版本方式渲染。 

使用下面这段代码后,开发者无需考虑网页是否兼容IE8浏览器,只要确保网页在IE6、IE7下的表现就可以了。 

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
//emulate 仿真 

给网站添加X-UA-Compatible标签 

我建议使用下面的X-UA-Compatible标签: 

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
IE=edge告诉IE使用最新的引擎渲染网页,chrome=1则可以激活Chrome Frame 

为了不掩盖重点,直接看 
2,问:X-UA-Compatible设为IE=edge是不是等同于不设置? 
既然IE=edge是“以最高级别的可用模式显示内容”,那是不是和去掉相同的效果? 

答:不一样。 
有些因素会自动触发兼容性文档视图,这个时候设置X-UA-Compatible就可以防止这个自动触发的行为。 
默认行为大致有这些: 
  存在于注册表中的兼容性视图列表,当url匹配时将自动切换到兼容性视图 
  在注册表中的对应字段指定了使用兼容性视图来显示所有网站 
  未指定DOCTYPE,则使用Quirks模式 
  曾经遇到过错误 

一个有意思的事实是,设置了<meta http-equiv="X-UA-Compatible" content="IE=edge">之后,即使未声明doctype,在IE8、IE9(未测试IE10+,不过行为应该类似)下面,页面也不会进入quirks模式。 

ref: http://msdn.microsoft.com/zh-cn/library/cc288325 

使用 X-UA-Compatible 标头可指定页面支持的 Internet Explorer 版本。 使用 document.documentMode 可确定网页的兼容性模式。 

<meta http-equiv="X-UA-Compatible" content="IE=5" /> 
像是使用了 Windows Internet Explorer 7 的 Quirks 模式,这与 Windows Internet Explorer 5 显示内容的方式很相似。 

<meta http-equiv="X-UA-Compatible" content="IE=7" /> 
无论页面是否包含 <!DOCTYPE> 指令,均使用 Windows Internet Explorer 7 的标准渲染模式。 

<meta http-equiv="X-UA-Compatible" content="IE=8" /> 
开启 IE8 的标准渲染模式,但由于本身 X-UA-Compatible 文件头仅支持 IE8 以上版本,因此等同于冗余代码。 

<meta http-equiv="X-UA-Compatible" content="edge" /> 
Edge 模式通知 Windows Internet Explorer 以最高级别的可用模式显示内容,这实际上破坏了“锁定”模式。 

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
EmulateIE7 模式通知 Windows Internet Explorer 使用 <!DOCTYPE> 指令确定如何呈现内容。标准模式指令以Windows Internet Explorer 7 标准模式显示,而 Quirks 模式指令以 IE5 模式显示。与 IE7 模式不同,EmulateIE7 模式遵循 <!DOCTYPE>
指令。对于多数网站来说,它是首选的兼容性模式。 
在现阶段,IE8 版本推向市场没有多久,份额不高。因此,考虑兼容旧版本的模式值得推荐。 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: