Reputation:
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
Upvotes: 2
Views: 2242
Reputation: 2892
Just access the frames collection and use the document in the usual way. For example:
window.frames['loader_frame'].document.getElementById("ad_nr")
Upvotes: 0
Reputation: 2332
You can use the window.frames array to access child frames. Example:
window.frames[0].document.getElementById('myElement')
Upvotes: 0
Reputation: 82523
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.
Upvotes: 0
Reputation: 888185
You can use the window.frames
collection.
For example:
window.frames[index].document.getElementById('myInputName').value = someValue;
Upvotes: 2