您的位置:首页 > 其它

IE文档模式和浏览器模式的为什么和怎么样的思考

2011-10-19 22:33 267 查看
正在使用IE8&&IE9的哥们和妹子们可能已经正在使用F12来打开开发者工具,并且使用”浏览器模式“和”文档模式“;这些工具基本上都是用来测试和确信你的网页在多种IE版本中的运行和显示。
web开发者能够熟练地使用浏览器模式和文档模式,但是我们中的很多人却不知道他们两者的不同之处,和什么时候使用。如果你正在使用ECMAscript 5对象模型(在ie9中支持)并且想要再低版本中看到回馈效果,你将会使用哪一个模式来测试呢?浏览器模式还是文档模式?首先,为什么按了F12以后工具里面会有两个这个的选项呢?他们产生的道理何在?
Browser mode: To test for different versions of IE, the "Browser mode" option in F12 tools can be used. It sets the user-agent string to the browser mode option which is chosen and sends HTTP request to the server (this is a full postback). The site then responds with an appropriate document type, based on the doctype and X-UA-Compatible header.

So, if you select IE8 browser mode, IE will present the page in a way which IE8 user experiences. Also, since the user-string is sent in HTTP request to the server, the browser detection code written in C# (as seen in the above section) works and all server side manipulations can be done.

Document mode: The document mode essentially decides the mode in which IE's rendering engine (Trident) should display the markup. In other words, changing the document mode in F12 tools will have exactly the same effect as specifying your own X-UA-Compatible header in your web page. The main difference from browser mode is, when document mode is changed, there will NOT be a fresh request to the server and hence the user-agent string will NOT be sent. Its only that the rendering engine displays content according to your choice.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: