Majax
Majax

Reputation: 15

Locating a frame contained iframe from a sibling frame

My web page is made of 2 frames with the name and id attributes set to "left" and "center".

I run a JS script in the left one to be able to locate/identify an iframe with name and id "monfrm" in the center frame.

Here is the JavaScript I have so far:

x = top.document.getElementById("center");
alert(x.src);   //fine
// ok up to here
y = x.getElementById("monfrm");  // attempting to locate my iframe within "center" frame & that's where it hurts
alert("left says" + y.width);   //eeh nothing

I'm probably getting old cos' it seems pitifully easy unless I missed a point.... :-)

Any light shed welcome

Thanks

Upvotes: 1

Views: 164

Answers (1)

arcyqwerty
arcyqwerty

Reputation: 10695

If you want to use getElementById to select within a frame/iframe, you need to call it on the frame's contentWindow.document as shown here:

document.getElementById('myframe1').contentWindow.document.getElementById('x')

Given your code, you would want to set

y = x.contentWindow.document.getElementById("monfrm");

Upvotes: 1

Related Questions