frame 之间访问

时间:2023-03-08 17:15:13

index.asp代码

<frameset rows="50,*,20" cols="*" frameborder="no" border="0" framespacing="0">
<frame src="Top.aspx" id="iframeTop" scrolling="no" noresize>
<frameset id="fs" rows="*" cols="150,9,*" frameborder="no" border="0" framespacing="0">
<frame src="Left.aspx" id="iframeLeft" scrolling="auto" frameborder="NO" border="0" framespacing="0">
<frame src="Split.aspx" scrolling="auto" frameborder="NO" border="0" framespacing="0">
<frame name="Right" id="Right" src=<%=strRightURL %> scrolling="auto" frameborder="NO" border="0" framespacing="0">
</frameset>
<frame name="Bottom" id="Bottom" src="Bottom.aspx" scrolling="NO" noresize>
</frameset>

frame Right 中某个页面要访问其他frame的控件:

   var oDoc = top.parent.document;
var oFrameLeft = oDoc.frames["iframeLeft"];
oFrameLeft.document.getElementById("mdiv").style.height = oFrameLeft.document.body.offsetHeight;
oFrameLeft.document.getElementById("mdiv").style.width = oFrameLeft.document.body.offsetWidth;
var oFrameTop = oDoc.frames["iframeTop"];
oFrameTop.document.getElementById("mdiv").style.height = oFrameTop.document.body.offsetHeight;
oFrameTop.document.getElementById("mdiv").style.width = oFrameTop.document.body.offsetWidth;

mdiv为Left中的一个div,如果要访问到,必须要有body,且在body里面。不然document.getElementById("mdiv").style报错。