cannot get scrollHeight of dynamically loaded iFrame

Posted on 2007-10-21
Last Modified: 2010-01-31
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?


Question by:andy7789
    1 Comment
    LVL 3

    Accepted Solution

    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......."

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now