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
134k31 gold badges214 silver badges613 bronze badges
asked Oct 11, 2010 at 14:09
2

1 Answer 1

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');
answered Oct 11, 2010 at 14:11
Sign up to request clarification or add additional context in comments.

3 Comments

Exactly where I shall try those? After the iframe? Or for the javascript code of index.cgi..
You would use this from the containing page, possibly from the onload event of the iframe.
You must have called it before the node was loaded. Make sure to call it after onload, or after the close body tag

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.