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
134k31 gold badges214 silver badges613 bronze badges
asked Oct 11, 2010 at 14:09
Luci
3,3047 gold badges34 silver badges37 bronze badges
-
stackoverflow.com/questions/2947082/…mplungjan– mplungjan2010年10月11日 14:11:29 +00:00Commented Oct 11, 2010 at 14:11
-
possible duplicate of How to auto-size an iFrame?Matt Ball– Matt Ball2010年10月11日 14:12:12 +00:00Commented Oct 11, 2010 at 14:12
1 Answer 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');
Sign up to request clarification or add additional context in comments.
3 Comments
Luci
Exactly where I shall try those? After the iframe? Or for the javascript code of index.cgi..
tKe
You would use this from the containing page, possibly from the onload event of the iframe.
Ruan Mendes
You must have called it before the node was loaded. Make sure to call it after onload, or after the close body tag
lang-js