title: Uncaught ReferenceError: XXX is not defined at first, no errors when refresh
body: <p>I'm having a unique problem (I have been looking for hours now)
  I am trying to create an iFrame, using only javascript</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    &lt;script&gt;
      function resize(obj) {
          obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
          obj.style.height = 0;
          obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
      }
      &lt;/script&gt;
  
      &lt;iframe  frameborder="0" width="1000" scrolling="no" onload="resize(this)" src="/myurl.url"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>When I reach the page for the first time, I get this error in the console log:</p>
  
  <p><strong>Uncaught ReferenceError: resize is not defined
      at HTMLIFrameElement.onload</strong></p>
  
  <p>So the iFrame isn't the right height...</p>
  
  <p>But the weird part is when I <strong>Reload/refresh (ctrl+R)</strong> the page, <strong>there is no errors</strong>, and the iFrame is at the correct height ! Only the reload will work, If I press Back et click on the page again, I will get the errors. Once I press Reload, I can go back and forth with no errors !</p>
  
  <p>I can't find any logic in that... Any ideas?</p>
  
  <p>Thanks</p>