1

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

arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
Majax
  • 15
  • 3

1 Answers1

1

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");
Community
  • 1
  • 1
arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
  • You guys are terrific , both comments led me to fix the issue thanks a lot – Majax Oct 16 '15 at 07:24
  • If your question has been answered, please consider marking the answer as accepted (checkmark on the left) so the question can be closed. :) – arcyqwerty Oct 16 '15 at 14:55