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

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

问题描述

让我们假设你有一个比较严格的DOCTYPE和HTML标记这是pretty接近标准的网页,但也许错过的也许是因为用户内容那是你无法控制的一些愚蠢的方式,...说你重新工作的一个内容管理系统或内容管理系统,你控制的一些基本结构和需要一些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浏览器,浏览器,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天全站免登陆