title: How do I resize an iframe with dynamic content?
body: <p>I'm populating an iframe with some contents that are injected into it but I'm unable to size it correctly.  I've tried a variety of methods but here is the most recent code.</p>
  
  <p>After populating the iframe with an html based mail message it doesn't seem to register the scroll height.</p>
  
  <pre><code>    &lt;iframe scrolling="no" width="100%" onload="javascript:(LoadIFrame(this));" &gt;
  HTML content goes here.  Make sure it's long enough to need to scroll before testing.
  &lt;/iframe&gt;
  
  &lt;script type="text/javascript"&gt;
      function LoadIFrame(iframe) {
          $("iframe").each(function() {
              $(this).load(function() {
                  var doc = this.document;
                  if (this.contentDocument) {
                      doc = this.contentDocument;
                  } else if (this.contentWindow) {
                      doc = this.contentWindow.document;
                  } else if (this.document) {
                      doc = this.document;
                  }
                  this.height = (doc.body.scrollHeight + 50) + 'px';
                  this.onload = '';
              });
  
              txt = $(this).text();
              var doc = this.document;
              if (this.contentDocument) {
                  doc = this.contentDocument;
              } else if (this.contentWindow) {
                  doc = this.contentWindow.document;
              } else if (this.document) {
                  doc = this.document;
              }
              doc.open();
              doc.writeln(txt);
              doc.close();
          });
      }
  &lt;/script&gt;
  </code></pre>