title: Adjust Iframe height dynamically and set scroll if content height change on client side event (Text Expand/Collapse using +/- buttons)
body: <p>I have been searching around for a solution to set scroll of iframe sourcing same domain page using javascript. I just want to have scroll on the iframe only if the content's height is greater that the window height. Came across solutions using setInterval. In IE i dont get a proper scrollheight for a page that has some content hidden. The works fine in chrome and mozila although. Also it looks like i have to set anyways max-hright of the iframe to get this code working on chrome and IE when the use click on +/- in the iframe page. I dont have controll over the source page for iframe. Also there are events where in the content height of the iframe changes at client side like expand/collapse thing. Any suggestions as to why it is happening or any other options to implement.</p>
  
  <p>Iframe container (div)</p>
  
  <pre><code>    border: groove;border-width: thin;display:none;position:fixed;z-index:998;width:800px;background-color: white;right: 83px;top:22px;
  </code></pre>
  
  <p>Iframe style </p>
  
  <pre><code>    top: 20px;margin:0;padding:0
  </code></pre>
  
  <p>Javascript function that gets called based on interval to set iframe height to that content height</p>
  
  <pre><code>    function AdjustIframeHeightOnLoad() {
  
  
  var screenHeight = $(window).height();
  var iframeContentHeight;
  
  var iframeContentwidth;
  
  iframeContentHeight = document.getElementById("iframe_ObjectLink").contentWindow.document.body.scrollHeight;
  
  iframeContentwidth = document.getElementById("iframe_ObjectLink").contentWindow.document.body.scrollWidth;
  
  
  if (iframeContentHeight &gt; (screenHeight - 47)) {
      document.getElementById("objectionMenuContentContainer_div").style.height = (screenHeight - 27) + "px";
    document.getElementById("iframe_ObjectLink").height = (screenHeight - 47);
      document.getElementById("iframe_ObjectLink").contentWindow.document.documentElement.style.overflowY = "scroll";
  }
  else {
      document.getElementById("objectionMenuContentContainer_div").style.height = iframeContentHeight + "px";
      document.getElementById("iframe_ObjectLink").height = (iframeContentHeight - 25);
      document.getElementById("iframe_ObjectLink").contentWindow.document.documentElement.style.overflowY = "hidden";
  }
  
  if (iframeContentwidth &gt; 883)
      document.getElementById("iframe_ObjectLink").contentWindow.document.documentElement.style.overflowX = "scroll";
  else
      document.getElementById("iframe_ObjectLink").contentWindow.document.documentElement.style.overflowX = "hidden";
  </code></pre>
  
  <p>}</p>