Welcome to WebmasterWorld Guest from 220.127.116.11
Forum Moderators: open
When I debug through the frames loop and look at the properties returned by document.frames[x] it's nothing at all like the properties returned by a loop through getElementsByTagName('iframe').item(x).
So suppose I have an undetermined number of iframes on a page, and an undetermined number of frames. I already have a way of knowing that a particular frame in the loop is my iframe (explained later) but I can't work out which iframe that is. I need to know which iframe it is so I can get its offsetLeft and offsetTop properties. A frame reference returned by the frames array doesn't offer that information.
I need to find the offsetLeft and offsetTop positions of an iframe on a page so I can write a layer to that page in a position relative to the iframe. The iframe has no ID tag (and I have no way of ensuring it has one) or if it does, I don't know what it is. This iframe that I'm looking for is my pages great great grandparent (4 layers of nested iframes where the top and bottom iframes are in the same domain). So the great grandchild iframe has all rights to read/write in the great grandparent iframe. There's no problems there. The problem is finding out where my great grandparent is on the page so I can write next to it.
What I can already determine though is which element in the frames array is my iframe. I do this by getting a reference to it in the great grandchild iframe by doing "var grandparent=parent.parent". That gives me a 'reference' to the iframe that I'm trying to find on the great grandparent page. Now if I loop looking at parent.parent.parent.frames[x] and compare that reference with the 'grandparent' variable reference I find a match in the loop. The references are both to the same object so they match.
So now I know which element in the frames array of the great grandparent is my grandparent. Now if I could just ask it then what its offsetLeft or offsetTop are I'd be all set, but it's a frame at this point, not an iframe, because it's in the frames array, and a frame doesn't have those properties. What I'd need to do somehow is cast the reference to the frame to be a reference to an iframe and I'd get all of its properties. Alternately, find a way of determining which of the iframes corresponds to that frames array entry. Then I could access that iframe directly using getElementById (or something) and then I find the offsets.
When I look at the frames reference object it has very few properties. It has undefined location.href and if I try to overwrite it's 'name' and then look in the iframes array to find that name I have no luck.
So how can I take this found frame and reverse engineer the knowledge to find out which iframe "item" number it is from the getElementsByTag('iframe') loop? Because once I find it via an iframe loop also, I can ask it for its offset values.
-and then assigning the id of the frames[x] to the iframe? perhaps something like this pseudocode:
var id = frames;
newIframe = document[id]
I'm sceptical myself, but it's my best (wild) guess right now.
BTW: Welcome to WebmasterWorld :)
I think the problem here is that I'm trying to find out something about a frame (i.e. anything that can give me a clue to which iframe it is) and the cross-domain security won't let me get access to it. I can't find out its location, position, name, domain or anything.
I just need to be able to cast that reference to the frame to be a reference to the iframe (which it really is). A cross-domain iframe object will tell you more about itself while still maintaining cross-domain integrity.
There may well not be a way around this, and I don't want to exploit any current loopholes that haven't been fixed yet. They have a habit of getting plugged. (Not that I know one here anyway).
So when I find a matching reference in the frames array in a loop, I know I've found the right index number of my iframe. I take my loop index and use it to get the getElementsByTagName.item(x) correct iframe. I can then ask it for its offsetLeft and offsetTop. This works fabulously :)