views:

50

answers:

1

I need to access an id found inside an iframe. I have the following code:

print "<IFRAME id='preview_iframe_form' ... src=\"$server_url/index.cgi ";

Inside index.cgi, I have the following :

      print"<div id='result_div'>";
      &show_list();
      print "</div>";

I need to check the result_div height so set the height of preview_iframe_form

+1  A: 

Try this:

var iframe = document.getElementById('preview_iframe_form');
var iframedoc = iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
var resultEl = iframedoc.getElementById('result_div');
tKe
Exactly where I shall try those? After the iframe? Or for the javascript code of index.cgi..
zeina
You would use this from the containing page, possibly from the onload event of the iframe.
tKe
Thanks, it worked.
zeina
You must have called it before the node was loaded. Make sure to call it after onload, or after the close body tag
Juan Mendes