Our dev and corporate sites have a slightly different frame hierarchy.
Very occasionally I need to reference an element in a different frame.
Unfortunately, I don’t know where that frame will be in the hierarchy. I do however know it’s id.
How can I find a frame or the specific element, when I don’t know the exact structure?
For clarification
In dev, it’s basically just a page, containing a frame. I’m in the context of the frame, and was just using window.top.document to get the document I wanted.
In prod, the nesting is different, window.top.document doesn’t work, as it is inside of two other frames.
I can’t change this structure, it’s just how our application portal works.
maybe you could try traversing all the frames. you will either need to use a breadth-first or depth-first search depending on how deep the frame nesting will be. pass it the root originally.
I’m not 100% sure of the correctness of this recursive algorithm but this is the right idea I believe.
EDIT:
if you need to find the topmost parent, try:
this will check upwards first, then downwards if that doesn’t work