cannot get scrollHeight of dynamically loaded iFrame

Hi X-perts,

I need to adjust hight of iframe for dynamically loaded content (outside http). I have done it hundreds of times for the content loaded from the same server, but, in this case, cannot get an actual iframe body params. here is a simple code:

<iframe name="calc" id="calc" width="100%" height="480" allowtransparency="yes" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
<div class="mgunit" id="rd1"><a href="http://www......." class="pageLink" onclick="col_open(440)" target="calc" >This div should load iframe content from </a></div>

It loads an iframe just fine and next I am trying to find its hight:

function getHeight(){
var fName = 'calc';
 // var fName =;
  var h= document.getElementById(fName).document.body.scrollHeight;
  //var h= window.frames[fName];
  //var h= window.frames[fName].document.body.scrollHeight;
  //var h= window.frames[fName].document.body.offsetHeight ;


I tried all possible expressions like document.body.scrollHeight, or offsetHeight (for ns6) etc, but the second alert does not return anything (no errors either). Are there any tricks related to the outside content loaded into iframe? Any workaround?


Who is Participating?
aidinetConnect With a Mentor Commented:
try to make a server side page (php/asp ... etc) that reads the content of "http://www......." and load it in the iframe instead of "http://www......."
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.