title: How to get height of iframe contents as it changes?
body: <p>I have an iframe that loads in a page from my website and I need to set it's positioning to the center of the page dynamically based on the height of the iframe's content, and I have had no issues with the code that I am using except that the height of the iframe's content will never return a value lower than what it is if the content get's smaller (if that makes sense).</p>
  
  <p><strong>The js recognizes when the content height grows, but not when it shrinks.</strong></p>
  
  <p>E.g. if I have a page that is 400px high, and then some content dynamically changes to 420px, my code will recognize that it is 420px high, but then if it changes to 350px, for instance, my code will <strong>still see it as being 420px high</strong>. How do I fix this?</p>
  
  <p>Code:</p>
  
  <pre><code>function place()
  {
      var w = $(window).width();
      w-=1000;
      w/=2;
      if(w&lt;12)
      w = 12;
      $("#div").css("left",""+w+"px");
      $("#closeDiv").css("left",""+(w-12)+"px");
  
      var h = $(window).height();
      var ifh = document.getElementById("inner").contentWindow.document.body.scrollHeight;
      document.title = ifh;
      h -= ifh;
      h /= 2;
      if(h &lt; 20)
      h = 20;
      $("#div").css("top",""+h+"px");
      $("#div").css("height",""+ifh+"px");
      $("#closeDiv").css("top",""+(h-12)+"px");
  }
  </code></pre>
  
  <p>The document title continues to show the 420px, even when I know that the content is less than that. The same problem occurs for <code>.offsetHeight</code>.</p>
  
  <p>Thanks for your help!</p>
  
  <p><strong>SOLUTION UPDATE</strong></p>
  
  <p>Okay, so I used the code in the answer I marked as solving the problem, as I did use it and it deserves credit for helping me solve this problem, but the actual problem that was involved here was that I had the height of the iframe set to be 100% of the container box; as soon as I set it to 99%, that fixed the problem. Not sure why...but hey!</p>
  
  <p>Thanks for all of your help!</p>