DOCTYPE, iFrames, HTML5 - together

2019-05-03 21:24发布

问题:

I've got a situation where an iFrame needs to be embedded in a page. The iFrame uses the HTML 5 DOCTYPE (and associated elements) and I have it working correctly in the various browsers (IE flavors, mozilla, etc.). However, the main page that hosts the iFrame has a different DOCTYPE (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">).

When I view the resulting page in IE9 and use the "Dev Tools" I see that Browser Mode is set to IE9 and Document Mode gets set to IE7 standards. If I change the Document Mode to something besides Quirks, it looks fine.

回答1:

You can't make your iframe run in a different mode, sadly. One potential solution is to use XHTML-style syntax in your HTML5, which is valid HTML5 and will be recognised by the older rendering engine.