IE6 changes DOCTYPE to a bad one

寵の児 提交于 2019-12-10 23:37:21

问题


I am working with website that has defined following DOCTYPE:

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

When I access that website in IE6, DOCTYPE is magically changed to:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">

And.. Ok - it can stay because everything looks fine.. But here is the point - just one page has DOCTYPE changed to:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

which I can't stand.

What is the reason of changing XHTML to HTML 4.01 and HTML 4.0 ?

How can I force DOCTYPE in IE6 to XHTML or just HTML 4.01 ?


回答1:


The reason was unexpected:

HTML comment placed before <html> tag causes auto change of the page's doctype.




回答2:


A browser only displays pages, and never modifies the original page.

The only way your question makes sense is if you're doing "save page as" and wondering why the page that IE saved isn't the same as the page it downloaded. In this case I'd expect the browser converts the page into a some sort of internal representation to make it easier to process, and "save page as" converts that internal representation back into HTML; so that it can save a single file (e.g. with embedded CSS rather than a separate CSS file), ensure that the saved file has correct markup (rather than the original potentially un-corrected markup), etc.

If this isn't what you want, go to "view -> page source" and copy & paste that instead.




回答3:


The only important thing that the doctype does is to force the browser into standards compliance mode. If you don't have a doctype, older browsers will go into Quirks mode; with the doctype (no matter which one you use), the browser will go into Standards mode.

Therefore it really doesn't matter which one you use.

The XHTML doctypes will try to enforce XHTML compliance, but obviously only in browsers that properly support XHTML - IE6 may be problematic here. And of course, specifying XHTML means there's no room for any errors at all, or your page won't be rendered.

Other than that, there's really not much to choose between the various doctypes, so my suggestion is to go with the most up-to-date one possible.... which is the HTML5 doctype.

The HTML5 doctype looks like this:

<!DOCTYPE html>

That's all. Short, simple and to the point. And it does the job for all current browsers (including IE6).

This doesn't mean you have to use any HTML5 features (they obviously won't work IE6 anyway), but it's fully backward compatible, and shouldn't give you any of the weird browser-specific glitches you get with other doctypes.

Hope that helps.



来源:https://stackoverflow.com/questions/4658226/ie6-changes-doctype-to-a-bad-one

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