0

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

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Luci
  • 3,174
  • 7
  • 31
  • 36
  • http://stackoverflow.com/questions/2947082/whats-the-most-concise-cross-browser-way-to-access-an-iframe-elements-window – mplungjan Oct 11 '10 at 14:11
  • possible duplicate of [How to auto-size an iFrame?](http://stackoverflow.com/questions/247128/how-to-auto-size-an-iframe) – Matt Ball Oct 11 '10 at 14:12

1 Answers1

1

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
  • 560
  • 2
  • 9
  • Exactly where I shall try those? After the iframe? Or for the javascript code of index.cgi.. – Luci Oct 11 '10 at 14:14
  • You would use this from the containing page, possibly from the onload event of the iframe. – tKe Oct 11 '10 at 14:16
  • You must have called it before the node was loaded. Make sure to call it after onload, or after the close body tag – Ruan Mendes Oct 11 '10 at 14:41