Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you force IE to render in standards mode if you only have control of the contents of body?

I have a peculiar situation where I am only given control of the contents of a document's <body>. The host, I assume in an effort to remain flexible, is not declaring a doctype which will throw IE into quirks mode immediately. With my limited control over the document, what can I do to force IE to render the page in standards mode?

like image 677
David Gouldin Avatar asked Aug 01 '10 22:08

David Gouldin


People also ask

Why quirks mode?

quirks mode is for the old rules of browsers, they made it so that old websites that were written before the world wide web came and before HTML5 was invented don't break. so quirks mode is just to support those websites that had incorrect CSS features.

How do I enable quirks mode in ie11?

Once you have the hotfix deployed or you have installed IE9 on your computers you can then use the policy “Use Policy List of Quirks Mode sites” under Software\Policies\Microsoft\Internet Explorer\BrowserEmulation\QuirksPolicyList to add specific sites to render as quirks mode.

What role does the doctype play with these modes?

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.


2 Answers

I believe you can't do anything about it unless you say, rewrite the contents of the page dynamically with JS and forcefully insert a doctype.

Can you go into specifics of how much control you have over the <body>? Are you allowed to do JS/scripting?

EDIT: Here's an attempt but I didn't test it in IE. It may give you ideas. I document.write() the outerHTML of document.documentElement and it turns the compatMode into CSS1Compat.

You may need to strip out the script block upon rewrite. Like I said, I wouldn't really recommend trying this...

http://medero.org/first-line.html

EDIT #2: It seems to surprisingly work in IE6. But upon refresh, IE caches it somehow and it permanently stays in its .document.write()ed form. To counter that, append it with a query string, eg ?203984234.

Again, I'm not sure what your situation is, but I hope this gives you ideas or helps.

EDIT #3: I rewrote it and bound the document.write to window.onload. You will need to append a unique query string every time you visit it to see the effect, because it caches it after it .write's it.

http://medero.org/rewrite.html?f30324433322111

If you need something more instantaneous you can probably jack jQuery's DOM ready function to rewrite it before the window loads.


Miscellaneous Notes:

  • You could probably hide the entire html document through CSS until the document.write is invoked if visually it matters
  • You should probably strip the <script> document.write before saving outerHTML so that the newly written page doesn't have the script block.
like image 62
meder omuraliev Avatar answered Nov 15 '22 09:11

meder omuraliev


Have a look at this Defining Document Compatibility article on MSDN. Perhaps writing out the X-UA-Compatible meta tag will work.

like image 20
Douglas Avatar answered Nov 15 '22 08:11

Douglas