使用X-UA-Compatible来设置IE浏览器兼容模式

若项目中使用frameset 或者 ifame ,则需要设置最顶层页面的

X-UA-Compatible属性,之后内嵌的所有页面都会继承,不用再单独设置。


<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=8">
<title>上海申通地铁集团综合业务协同平台</title>
<frameset rows="79,*,35" frameborder="no" border="0" framespacing="0">
  <frame src="/portal/mainFrame/topp.jsp" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
  <!--<frame src="main_frame.html" name="mainFrame" id="mainFrame" title="mainFrame" />  -->
  <frameset id="main" cols="7,*" frameborder="no" border="0" framespacing="0">
  	<frame src="" class="frame_bl" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" title="leftFrame" />
  	<frame src="" class="frame_br" name="mainFrame" id="mainFrame" title="mainFrame" />
	</frameset>
  <frame src="bottom.jsp" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomFrame" title="copyright" />
</frameset>
<noframes><body>
</body></noframes>
</html>



X-UA-Compatible 无效

近做个网站的项目中,遇到X-UA-Compatible无效的问题。
经测试,X-UA-Compatible只有在前面也有meta的时候,才有效。
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
这是给IE8看的,以兼容(IE7)模式呈现网页。


翻了下MSDN《定义文档兼容性》,里面有这么一句:

X-UA-compatible 标头不区分大小写;不过,它必须显示在网页中除 title 元素和其他 meta 元素以外的所有其他元素之前的标头(HEAD 节(可能为英文网页))中。

MSDN有机器翻译的传统,再看下英文版

The X-UA-compatible header is not case sensitive; however, it must appear in the Web page’s header (the HEAD section) before all other elements, except for the title element and other metaelements.



x-ua-compatible 用来指定IE浏览器解析编译页面的model

x-ua-compatible 头标签大小写不敏感,必须用在 head 中,必须在除 title 外的其他 meta 之前使用。
1、使用一行代码来指定浏览器使用特定的文档模式。
<meta http-equiv="x-ua-compatible" content="IE=9" >
<meta http-equiv="x-ua-compatible" content="IE=8" >
<meta http-equiv="x-ua-compatible" content="IE=7" >
 
2、在一些情况下,我们需要限定浏览器对文档的解析到某一特定版本,或者将浏览器限定到一些旧版本的表现中。可以用如下的方式:
<meta http-equiv="x-ua-compatible" content="IE=EmulateIE9" >
<meta http-equiv="x-ua-compatible" content="IE=EmulateIE8" >
<meta http-equiv="x-ua-compatible" content="IE=EmulateIE7" >
 
使用这种写法,浏览器或者使用标准模式进行解析,或者使用 IE5 Quirks 模式进行解析。
 
3、为了测试,我们也可以使用下面的语句指定浏览器按照最高的标准模式解析页面。
<meta http-equiv="x-ua-compatible" content="IE=edge" >
 
4、多个模式的指定。我们可以用逗号分割多个版本,这种情况下,浏览器会从这个列表中选择一个他所支持的最高版本来使用标准模式进行渲染。如下面的例子,在IE8进行浏览时,将会使用IE7的标准模式进行渲染,因为他本身不支持IE9和IE10。
<meta http-equiv="x-ua-compatible" content="IE=7,9,10" >
参考:
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值