2

Im familiar with accessing parent windows like this:

window.parent.document.getElementById("ad_nr")

But what if I want to access a child window from a parent? (iframe for example) and then set a hidden input in there to some value created in the parent window, how is this done?

Probably easy but I have missed it, so Im asking you guys!

Thanks

4 Answers 4

2

You can use the window.frames collection.

For example:

window.frames[index].document.getElementById('myInputName').value = someValue;
Sign up to request clarification or add additional context in comments.

Comments

0
frames["FRAME_NAME_HERE"].document.getElementById("HiddenField1").value = "Whatever";

Note: the document in the iframe must reside on the same domain as the parent. There is no getting around this restriction.

Comments

0

You can use the window.frames array to access child frames. Example:

window.frames[0].document.getElementById('myElement')

Comments

0

Just access the frames collection and use the document in the usual way. For example:

window.frames['loader_frame'].document.getElementById("ad_nr")

Comments

Your Answer

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