Doctype meta and quirksmode

筅森魡賤 提交于 2019-12-10 21:38:13

问题


Please can I clarify some thinking here:

Quirksmode is invoked if no doctype is specified.

but

When served from localhost IE appears to go into quirksmode regardless of doctype. Please can this be confirmed and can someone explain why this is the case.

however

When served from localhost and IE goes into quirksmode regardless of doctype this can be overridden by including a meta tag in the first line of the head

<meta http-equiv="X-UA-Compatible" content="IE=edge">

This doesn't work for me ... have I got the syntax wrong?

The meta in the head will only ever be applied when served from localhost? Is this true if so why.

At the moment everything looks fine in FF Chrome Opera etc whether served from localhost or across the net.

But I just get quirks mode in IE

My doctype is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Finally is there a relationship between charset and quirksmode?

I have been using

<meta http-equiv="content-type" content="text/html; charset=utf-8" />       

On apache with apache config set to default to UTF-8


回答1:


Quirks Mode is quirky, and you should not rely on anything particular regarding it. The situations where it is triggered are browser-dependent, but if you have seen an XHTML doctype, conforming to XHTML specs, to trigger it, then it’s probably a mistake in observations. You might have e.g. some stuff before the doctype. Ditto for the magic meta tag regarding IE.

You may have the syntax wrong, but not in the snippets posted.

Or the issue could be caused by some of the IE8 and IE9 complications in doctype sniffing.

There is no relationship between charset and Quirks Mode.




回答2:


Two things, you can try IE=8 etc....

You may also want to check doctype; although, it looks correct you might have hidden characters etc.... try using a basic editor that will show hidden characters.

For VI you can look at: http://www.chrispian.com/quick-vi-tip-show-hidden-characters/.

This would be a first step for me.




回答3:


Short answer

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

Is where it goes wrong, because you say it's text/html while your doctype is xhtml. You should use application/xhtml+xml.

Longer answer

It seems to me that you have not properly researched what XHTML actually is. This is a very strange kind of document. XHTML was supposed to be an improvement on traditional HTML but it never really got popular and generally it's not recommend that you use it unless you have very specific reasons.

Have a look at this web site. Some important sections:

XHTML 1.1

For the 1.1 version of XHTML the specifications are clear: text/html MAY NOT be used. The XHTML "native" content type of application/xhtml+xml SHOULD be used, whilst the generic XML content type of application/xml MAY be used.

This soup of content types leaves us with a fairly clear course of action for 1.1: if we use XHTML 1.1 2, we should serve application/xhtml+xml as the content type.

And here's your problem specifically:

The horror! The Horror!

You've guessed it. Serving up a document containing what is to all intents and purposes XHTML as text/html simply means that browsers will jump into error correcting mode and deal.




回答4:


I wanted to summarise the findings from this question.

To switch off compatibility mode in IE9

  1. in IE 9 right click tools icon and select command bar
  2. from command bar select tools
  3. from tools select Compatibility View Settings
  4. uncheck display intranet site in compatibility mode
  5. from command bar select tools ensure compatibility view is unchecked
  6. Restart Browser

Main points for changing code

  • The html 5 doctype simplifies the whole issue of setting a doctype.
  • The reason that there appeared to be a relationship between charset and quirksmode was the error in the meta to add that charset which put it in conflict with the doctype.

So actions completed to resolve problem.

  1. Ignore localhost quirksmode - this is only significant when testing.
  2. Use <!Doctype html> ensuring that the html document commences with this. N:B this does not mean that this has to be the first line of the HTML. php includes can precede it.

  3. In the <head> Use <meta charset="UTF-8">

  4. In php initialize use <?php header("content-Type: text/html; charset=utf-8"); ?>


来源:https://stackoverflow.com/questions/13499536/doctype-meta-and-quirksmode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!