Reputation: 329
I'm working within a setup that I have no control over:
Parent->Iframe->Iframe->My document
How do I access an element that is on the parent from within my document?
These are all on the same domain, so no cross-domain issues. I can do this with either straight up JS or jQuery.
I've been searching around, but haven't found any examples of someone trying to access an element on the top from the bottom through multiple iframes!
The solution, in case anyone else comes across this:
var p = $("#Viewport",window.top.document);
alert(p.attr('name'));
Upvotes: 1
Views: 315
Reputation: 10627
Just use window.top
, like:
console.log(top.document.getElementById('someInputId').value);
Notice that window
in implicit, so you can leave it off. Of course, you will have to change 'someInputId'
to an input id on your top page to see if this works. Use .innerHTML
instead of .value
if you are testing against an Element that is not an input.
Upvotes: 1
Reputation: 16
I believe you will be able to access this via window.parent, as thus:
window.parent.document.getElementById('target-element');
Upvotes: 0