您的位置:首页 > 其它

父页面里两个iframe之间互相访问

2009-05-09 08:54 429 查看
父页面里的代码里的两个iframe

<iframe id="frameLeft" height="100%" src="UserDeptLeft.htm">

</iframe>
<iframe id="frameRight" name="frameRight" src="Default.htm" height ="100%"></iframe>


左边的iframe 页里有控件:

<input type="hidden" id="moduleid" name="moduleid"/>

在右边的iframe访问左边的Iframe里的控件 moduleid

js 代码如下:

parent.frameLeft.window.document.getElementById("moduleid")

父页面访问左iframe里的控件 moduleid

js代码如下:

window.frames["frameLeft"].document.getElementById("moduleid")

网搜知识:

IE7兼容Iframe高度問題及Iframe問題

<body>
<iframe marginheight="0" marginwidth="0" src="Default.aspx" frameborder="0" scrolling="no" width="100%" id="info_iframe" name="info_content" onload="change_size()"></iframe>
</body>

<head>
<script language="javascript">
function change_size()
{
document.getElementById("info_iframe").style.height=info_content.document.body.scrollHeight+1+"px";
}
</script>
</head>

防止被人frame
<SCRIPT LANGUAGE=JAVASCRIPT><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>

所谓自适应,是指iframe的高度,由iframe里的页面内容高度来决定,

并设置iframe的边框为0,

无滚动条, 这样就看不出iframe的真正的高度啦

上面的chang_size方法,应用不是太好,

又在网上查了资料

方法不错,放在blog里,为学习之用.

function TuneHeight() {
debugger;
var frm = document.getElementById("frameLeft");
var subWeb = document.frames ? document.frames["frameLeft"].document : frm.contentDocument;
if(frm != null && subWeb != null) {
frm.height = subWeb.body.scrollHeight;
}


<iframe id="frameLeft" width ="25%" height="100%" src="Left.htm" onload="TuneHeight()"></iframe>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: