title: Main web page in standard mode, iframe in compatibility mode: any issues?
body: <p>We have some legacy HTML content which we must render in compatibility mode. The requirement comes from our customers who want their HTML-based reports (some of which were created back in IE6 days) to look and print exactly the same, regardless of the browser version or underlying technologies. At the same time, we want to use Standard Mode and HTML5 for the rest of our web app.</p>
  
  <p>An obvious solution is to host the legacy content in an <code>&lt;iframe&gt;</code> in compatibility mode. The following appears to work cross-browser:</p>
  
  <p><strong>main.html</strong> (in standard mode):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;style type="text/css"&gt;
          body {
              font-family: Arial;
              font-size: 9pt;
              font-style: italic;
              font-weight: bold;
          }
      &lt;/style&gt;
      &lt;script type="text/javascript"&gt;
          window.onload = function () {
              info.firstChild.data = "document.compatMode: " + document.compatMode;
              // test frame's HTML5 API: document.getSelection()
              setInterval(function () {
                  var selection = document.getElementById("contentFrame").contentDocument.getSelection();
                  var selectedNode = selection.focusNode;
                  if (selectedNode)
                      info2.firstChild.data = "Selected node: " + selectedNode.nodeName + ", offset: " + selection.focusOffset;
                  else
                      info2.firstChild.data = "";
              }, 500);
  
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Standard Mode Page&lt;/h1&gt;
      &lt;span&gt;body font&lt;/span&gt;
      &lt;table border="1"&gt;
          &lt;tr&gt;
              &lt;td&gt;Table font&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;span&gt;body font&lt;/span&gt;
      &lt;pre id="info"&gt;&amp;nbsp;&lt;/pre&gt;
      &lt;pre id="info2"&gt;&amp;nbsp;&lt;/pre&gt;
      &lt;iframe id="contentFrame" style="width: 500px; height: 300px;" src="frame.html"&gt;&lt;/iframe&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>frame.html</strong> (in compatibility mode):</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ""&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;style type="text/css"&gt;
          body {
              font-family: Arial;
              font-size: 9pt;
              font-style: italic;
              font-weight: bold;
          }
      &lt;/style&gt;
      &lt;script type="text/javascript"&gt;
          window.onload = function () {
              info.firstChild.data = "document.compatMode: " + document.compatMode;
              editable.focus();
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Compatibility Mode Frame&lt;/h1&gt;
      &lt;span&gt;body font&lt;/span&gt;
      &lt;table border="1"&gt;
          &lt;tr&gt;
              &lt;td&gt;Table font&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;span&gt;body font&lt;/span&gt;
      &lt;pre id="info"&gt;&amp;nbsp;&lt;/pre&gt;
      &lt;div id="editable" contentEditable="true" style="border: 1px dotted red"&gt;
          Editable
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Note the difference in rendering the <code>table</code></strong>, using the same CSS:</p>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/oNEUT.png" alt="Standard and compatibility mode mix"></p>
  
  <p>My question to experienced web developers: <strong>is this a supported scenario</strong> which can be used in production environment (IE8+ mostly, but occasionally Safari/Chrome/Firefox)? <strong>Is there a better way of doing this?</strong></p>
  
  <p>I've stumbled upon a related, albeit opposite <a href="https://stackoverflow.com/questions/12641511/trying-to-use-ie-edge-x-ua-compatible-in-an-iframe-on-a-page-using-ie-emulateie7">question</a>, which left me with mixed feelings.</p>
  
  <p><strong>[UPDATE]</strong> (based on the comments): </p>
  
  <p>All JavaScript resides inside the main page and appears to work just fine. What's interesting (and great!), the inner frame's view is rendered in compatibility mode, <strong>yet standard mode features are available for its DOM</strong> (at least, when accessed from the main page). E.g. <a href="http://msdn.microsoft.com/en-us/library/ie/ff975169%28v=vs.85%29.aspx" rel="nofollow noreferrer">document.getSelection</a> works (and does cross-browsers, too).</p>
  
  <p>By <strong>supported scenario</strong> I mean any endorsement by W3C HTML and DOM standards. So far I haven't found a definitive answer to this. This behavior may as well be just a nice side effect, although the fact it works cross-browsers is promising.</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/jj676915%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN</a> says the following: <em>As of IE9 mode, webpages cannot display multiple document modes. For example, consider a standards-based webpage that contains a frame element that displays content in quirks mode. IE9 mode displays the child frame in standards mode (because the parent document is in standards mode).</em> According to my tests, <strong>this is not true</strong>; my sample works as desired in IE9: the main page is in standard mode, the frame page is in quirk mode. <strong>[EDITED]</strong> As pointed out in the comments, it is the <a href="http://msdn.microsoft.com/en-us/library/ff405912%28v=vs.85%29.aspx" rel="nofollow noreferrer">Almost Standard Mode</a> (i.e., not the classic quirk mode), with its <a href="http://msdn.microsoft.com/en-us/library/gg558047%28v=vs.85%29.aspx" rel="nofollow noreferrer">own rendering rules</a>.</p>