2015-10-15 85 views
1

我的网页由2 frame s组成,其中nameid属性设置为“左”和“中”。从兄弟框架中找到包含iframe的框架

我运行在左一个JS脚本能够定位/在中央框架识别iframenameid“monfrm”。

这里是JavaScript我到目前为止:

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 

我可能老了COS'似乎容易得可怜,除非我错过了点.... :-)

任何光棚欢迎

感谢

+0

是'width'有效的HTML元素属性?也许尝试'offsetWidth'可以解决你的问题。 – Federico

+0

看在控制台上。你会有一个关于getElementById的错误 –

回答

1

如果你想使用getElementByIdframe/iframe内选择,你需要CA LL它的框架的contentWindow.document如图here

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

鉴于你的代码,你想设置

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

你们真是太棒了,这两个评论都让我解决了这个问题,非常感谢 – Majax

+0

如果你的问题已经得到解答,请考虑将答案标记为已接受(左边的复选标记),以便问题可以被关闭。 :) – arcyqwerty