如何判断浏览器是否处于“怪癖"状态?模式? [英] How to tell if a browser is in "quirks" mode?

查看:23
本文介绍了如何判断浏览器是否处于“怪癖"状态?模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个页面具有相对严格的文档类型和 HTML 标记,非常接近合规性,但可能会以一些愚蠢的方式遗漏,也许是因为用户内容超出了您的控制......假设您正在工作在内容管理系统或内容管理系统的主题上,您可以控制一些基本结构并需要一些 JavaScript,但您不对进入页面的所有其他内容负责.

Let's suppose you have a page with a relatively strict doctype and HTML markup that's pretty close to compliant, but perhaps misses in a few silly ways, perhaps because of user content that's out of your control... say you're working on a content management system or a theme for a content management system where you control some basic structure and need some javascript, but you're not responsible for everything else that goes into pages.

当浏览器决定进入怪癖"模式而不是使用它更符合标准的引擎时,你怎么知道(或:什么将决定)?

How can you tell (or: what will determine) when the browser decides to go into "quirks" mode rather than use it's more standards compliant engine?

我正在为每个主要浏览器寻找答案,因为 IE、Chrome、Safari 和 Firefox 当然都会以不同的方式处理这些问题.一个错误足以强迫它还是你有一些回旋余地?

I'm looking for answers for each of the major browsers, since IE, Chrome, Safari, and Firefox will of course all handle that differently. Is one single error enough to force it or do you have some leeway?

推荐答案

Firefox 和 Opera 中,您可以通过检查页面信息来确定您的浏览器是否处于怪癖模式".

In Firefox and Opera you can determine if your browser is in "quirks mode" by checking page info.

使用 document.compatMode,将告诉您大多数浏览器所处的模式.

Using document.compatMode, will tell you the mode you are in with most browsers.

Chrome、Safari 和 IE 中,在地址栏中运行此 javascript:

In Chrome, Safari, and IE, run this javascript in the address bar:

 javascript:window.alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode.')

(请注意,由于最近的安全更改,您需要在粘贴到地址栏中后重新键入 javascript: 部分)

(note that you'll need to re-type the javascript: portion after pasting into your address bar, due to recent security changes)

这篇关于如何判断浏览器是否处于“怪癖"状态?模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆