document.compatMode,quirks mode and standards mode
Document.compatMode
Indicates whether the document is rendered in Quirks mode or Standards mode.
SyntaxEDIT
mode = document.compatMode
ValuesEDIT
"BackCompat"if the document is in quirks mode;"CSS1Compat"if the document is in no-quirks (also known as "standards") mode or limited-quirks (also known as "almost standards") mode.
mode- Is an enumerated value that can be:
Note: all these modes are now defined in standards, so the older "standards" and "almost standards" names are nonsensical and no longer used in standards.
ExampleEDIT
if (document.compatMode == "BackCompat") {
// in Quirks mode
}
Quirks Mode and Standards Mode
In the old days of the web, pages were typically written in two versions: One for Netscape Navigator, and one for Microsoft Internet Explorer. When the web standards were made at W3C, browsers could not just start using them, as doing so would break most existing sites on the web. Browsers therefore introduced two modes to treat new standards compliant sites differently from old legacy sites.
There are now three modes used by the layout engines in web browsers: quirks mode, almost standards mode, and full standards mode. In quirks mode, layout emulates nonstandard behavior in Navigator 4 and Internet Explorer 5. This is essential in order to support websites that were built before the widespread adoption of web standards. In full standards mode, the behavior is (hopefully) the behavior described by the HTML and CSS specifications. Inalmost standards mode, there are only a very small number of quirks implemented.
How do browsers determine which mode to use?EDIT
For HTML documents, browsers use a DOCTYPE in the beginning of the document to decide whether to handle it in quirks mode or standards mode. To ensure that your page uses full standards mode, make sure that your page has a DOCTYPE like in this example:
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8>
<title>Hello World!</title>
</head>
<body>
</body>
</html>
The DOCTYPE shown in the example, <!DOCTYPE html>, is the simplest possible, and the one recommended by HTML5. Earlier versions of the HTML standard recommended other variants, but all existing browsers today will use full standards mode for this DOCTYPE, even the dated Internet Explorer 6. There are no valid reasons to use a more complicated DOCTYPE. If you do use another DOCTYPE, you may risk choosing one which triggers almost standards mode or quirks mode.
Make sure you put the DOCTYPE right at the beginning of your HTML document. Anything before the DOCTYPE, like a comment or an XML declaration will trigger quirks mode in Internet Explorer 9 and older.
In HTML5, the only purpose of the DOCTYPE is to activate full standards mode. Older versions of the HTML standard gave additional meaning to the DOCTYPE, but no browser has ever used the DOCTYPE for anything other than switching between quirks mode and standards mode.
See also a detailed description of when different browsers choose various modes.
XHTML
If you serve your page as XHTML using the application/xhtml+xml MIME type in the Content-Type HTTP header, you do not need a DOCTYPE to enable standards mode, as such documents always use full standards mode. Note however that serving your pages as application/xhtml+xml will cause Internet Explorer 8 to show a download dialog box for an unknown format instead of displaying your page, as the first version of Internet Explorer with support for XHTML is Internet Explorer 9.
If you serve XHTML-like content using the text/html MIME type, browsers will read it as HTML, and you will need the DOCTYPE to use standards mode.
How do I see which mode is used?EDIT
In Firefox, select View Page Info from the context menu, and look for Render Mode.
In Internet Explorer, press F12, and look for Document Mode.
What are the differences between the modes?EDIT
See the list of quirks and almost standards mode for the differences between the modes.
https://developer.mozilla.org/en-US/docs/Web/API/Document/compatMode
https://developer.mozilla.org/en-US/docs/Quirks_Mode_and_Standards_Mode
document.compatMode,quirks mode and standards mode的更多相关文章
- document.compatMode简介
对于document.compatMode,很多朋友可能很少接触,知道他的存在却不清楚他的用途.今天在ext中看到 document.compatMode的使用,感觉这个对于我们开发兼容性的web页面 ...
- document.compatMode属性介绍
之前不了解这个属性,今天总结一下,以后可能会用到. 对于document.compatMode,很多朋友可能都根我一样很少接触,知道他的存在却不清楚他的用途.今天在ext中看到 document.co ...
- document.compatMode介绍
来自:http://www.cnblogs.com/fullhouse/archive/2012/01/17/2324706.html 问题描述:看到阮一峰的博客里面的代码使用到了document.c ...
- 转 document.compatMode介绍
对于document.compatMode,很多朋友可能都根我一样很少接触,知道他的存在却不清楚他的用途.今天在ext中看到 document.compatMode的使用,感觉这个对于我们开发兼容性的 ...
- 前端面霸系列(1):doctype 、Quirks Mode & Standards Mode 、document.compatMode
近几日,气压猛降,雾霾铺天盖地,眼看一场腥风血雨就要在前端江湖爆发,这场战争不仅是百度.腾讯.阿狸.搜狐网易新浪等江湖豪门抢夺人才的大战,也是诸位江湖人士重新洗牌的好时机.每年10月,江湖的波动胜过华 ...
- javascript document.compatMode属性
文档模式在开发中貌似很少用到,最常见的是就是在获取页面宽高的时候,比如文档宽高,可见区域宽高等. IE对盒模型的渲染在 Standards Mode和Quirks Mode是有很大差别的,在Stand ...
- document.compatMode(判断当前浏览器采用的渲染方式)
转载自:http://www.cnblogs.com/fullhouse/archive/2012/01/17/2324706.html IE对盒模型的渲染在 Standards Mode和Quirk ...
- JS判断doctype文档模式-document.compatMode
IE对盒模型的渲染在 Standards Mode和Quirks Mode是有很大差别的,在Standards Mode下对于盒模型的解释和其他的标准浏览器是一样,但在Quirks Mode模式下则有 ...
- document.compatMode 浏览器渲染模式判定利器
在加了DOCTYPE的页面document.compatMode输出CSS1Compat,不管加的是XHTML的还是HTML5的DOCTYPE.没有加的输出BackCompat. BackCompat ...
随机推荐
- Nginx反向代理后应用程序获取客户端真实IP
Nginx反向代理后,Servlet应用通过request.getRemoteAddr()取到的IP是Nginx的IP地址,并非客户端真实IP,通过request.getRequestURL()获取的 ...
- FSCalendar使用和注意事项
相信大家项目中或多或少都有日历这一块的内容吧,公司作为教育行业的软件公司,当然也是一定有的. 最近被日历这一块的内容弄得很头疼啊,改来改去的,不过还是学到了很多东西,至少FSCalendar的使用基本 ...
- vue 使用 npm run dev命令后 自动打开浏览器
1.使用vue-cli 老版本构建项目时, 可修改config文件夹下index.js文件 autoOpenBrowser 属性给为 true 即可 使用vue-cli 3.x 版本后,所有的配置项均 ...
- 华为HCNA乱学Round 10:PPP&PAP
- python 连接Oracle 的步骤
1. 安装 cx_Oracle pip install cx_Oracle 2.配置 oci.dll 与 oraociei11.dll 添加到环境变量path中 下载地址:百度搜索下载,Oracle ...
- ajax提交表单包含文件
需要用到 FormData. html: <form id="formPost"> name: <input name="name" /&g ...
- nginx配置反向代理支持session
Nginx反向代理tomcat,很是方便,但是也有些细节的问题需要注意:今天遇到了这样一个问题,tomcat中路径“host/web1”,nginx中直接“host/”代理,这时候session就无法 ...
- PHP xdebug 断点调试
转载自: https://blog.csdn.net/qq_32631847/article/details/82054011
- 5.写一个sh脚本,可以通过一台机器控制多台机器
先创建一个脚步文件 对这个脚本进行编辑 [hadoop@node1 ~]$ vim xcall.sh 给脚本赋予权限 执行脚本 把脚本移动到 /usr/local/bin/目录下 [hadoop@no ...
- 【Linux-驱动】在sysfs下创建对应的class节点---class_create
在编写简单字符设备驱动的时候,可以使用宏class_create在sysfs下创建对应的class节点,便于用户管理设备: #define class_create(owner, name) \ ({ ...