title: content height of hidden iframe
body: <p>Like the title says I'm trying to set a hidden iframes height to match it's content but I keep getting very incorrect heights.</p>
  
  <p>I'm preloading a new (hidden) iframe with content and I need the height to be set before the iframe is set to be displayed by the user.</p>
  
  <p>I've been doing this with frames that are visible for a long time with ease but now that the frames are hidden when they are loaded it's acting up. I've looked through every corner of SO and have tried so many variations of basic functions but with no luck.</p>
  
  <p>I tried leaving the iframe visible, setting the height then hiding it, but the quick flash of the frame is unattractive. Is there a method that I'm just not aware of the get the ACTUAL content height from a hidden iframe?</p>
  
  <p>Open to jquery or plain js ideas. Here are two of the most common examples I've been working with. </p>
  
  <p>Any suggestions on this will be greatly appreciated. Thank you in advance.</p>
  
  <pre><code>// example 1 
  function resizeIframe(obj){
      obj.style.height = 0;
      obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
  
  portalDiv.append('&lt;iframe src="" scrolling="no" style="display:none;"&gt;&lt;/iframe&gt;');
  $('iframe').last().attr('src', '/content.php').load(function() {
      resizeIframe(this);
      // should return 363px
      // returns 1531px :(
  });
  
  // example 2
  portalDiv.append('&lt;iframe src="" scrolling="no" style="display:none;"&gt;&lt;/iframe&gt;');
  $('iframe').last().attr('src', '/content.php').load(function() {
      var contentHeight = $(this).contents().find(".container").height();
      $(this).height(contentHeight+"px")
      // should return 363px
      // returns 1531px :(
  });
  </code></pre>