iframe 父窗口和子窗口js相互的调用:
myFrame= document.getElementById("myFrame");
①、父窗口调用子窗 口:myFrame.window.functionName();
②、子窗品调用父窗 口:parent.functionName();
iframe 父窗口和子窗口之间属性访问:
①、 父窗口访问子窗口:iframe_ID.iframe_document_object.object_attribute = attribute_value
例 子:οnclick="iframe.mytext.innerText='http://www.baidu.com';"
②、子窗口调用父 窗口:parent.parent_document_object.object_attribute = attribute_value
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script>
/* 让iframe 自适应高度 */
function setFrameHeight(){
var lframe = document.getElementById("lframe");
var rframe = document.getElementById("rframe");
var lsubWeb = document.frames ? document.frames['lframe'].document : lframe.contentDocument;
var lsubWeb = document.frames ? document.frames['rframe'].document : rframe.contentDocument;
if(lframe != null && lsubWeb != null && rframe != null && rsubWeb != null){
lframe.height = lsubWeb.body.scrollHeight > rsubWeb.body.scrollHeight ? lsubWeb.body.scrollHeight:rsubWeb.body.scrollHeight;
rframe.height = lframe.height;
}
}
</script>
</head>
<body>
<table>
<tr>
<td>
<iframe id="lframe" name="lframe" src="left.jsp" frameborder="0" width="100%" height="100%" scrolling="auto" onLoad="setFrameHeight()"></iframe>
</td>
<td>
<iframe id="rframe" name="rframe" src="right.jsp" frameborder="0" width="100%" height="100%" scrolling="auto" onLoad="setFrameHeight()"></iframe>
</td>
</table>
</body>
</html>