title: How to properly scroll IFrame to bottom in javascript
body: <p>For a mockup-webpage used for research on interaction on websites, I created a mockup message-stream using JavaScript. This message stream is loaded in an IFrame and should show images at pre-set intervals and scroll to the bottom of the page after placing a new image at the bottom of the page. Getting the images to appear is working quite well with the provided script. However, both Chrome and IE seem to have trouble scrolling the page to the bottom. I would like to scroll to the bottom of the page as soon as the image is attached, but have for now added a 5 ms delay because that seemed to work sometimes. My questions are:</p>
  
  <ul>
  <li>Is it okay to use document.body.scrollHeight for this purpose?</li>
  <li>Can I make the scroll occur directly, or do I need a small interval before scrolling?</li>
  <li>How to make the code scroll to the bottom of the IFrame directly after adding an image?</li>
  </ul>
  
  <p>The following functions are used and trypost() is started onLoad:</p>
  
  <pre><code>function scrollToBottom(){
    window.scrollBy(0,document.body.scrollHeight);
  }
  
  function trypost(){
    point = point + 1;
    if(point &lt; interval.length){
      //create and append a new image
      var newImg = document.createElement("IMG");
      newImg.src = "images/"+images[point]+".png";
      document.getElementById('holder').appendChild(newImg);
      //create and append a return
      var br = document.createElement("br");
      document.getElementById('holder').appendChild(br);
      //time scroll to bottom (after an arbitrary 5 seconds)
      var stb = window.setTimeout(scrollToBottom, 5);
      //time next post
      var nextupdate = interval[point]*400;
      var tp = window.setTimeout(trypost, nextupdate);
    }
  }
  </code></pre>
  
  <p>My script section contains at least the following variables:</p>
  
  <pre><code>var point = -1;
  var interval = [10, 10, 15];
  var images = ["r1", "a1", "r2"];
  </code></pre>
  
  <p>This questions is a continuation of the project described in <a href="https://stackoverflow.com/questions/22676796/how-to-proper-use-settimeout-with-ie">How to proper use setTimeout with IE?</a></p>