frame的主窗口和子窗口之间通信

在frame中的子页面调用其他子页面的变量和方法:
1. parent.document.frames("子页面name").子页面方法();
2. parent.子页面name.子页面方法();
3. parent.frames["子页面name"].子页面方法();
例如:
1. parent.document.frames("top").tops();
2. parent.top.tops();
3. parent.frames["top"].tops();

在frame中主页面调用其他子页面的变量和方法:
1.子页面name.子页面方法()
2.子页面name.子页面变量

示例如下:
1、index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<frameset rows="80,*" cols="*" frameborder="no" border="0" framespacing="0">
<frame src="top.jsp" name="top" scrolling="No" noresize="noresize" id="top" />
<frameset cols="80,*" frameborder="no" border="0" framespacing="0">
<frame src="a.jsp" name="a" scrolling="No" noresize="noresize" id="a" />
<frame src="b.jsp" name="b" id="b" />
</frameset>
</frameset>
<noframes><body>
</body>
</noframes>
</html>



2、top.jsp

<%@ 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>top.jsp</title>
<script type="text/javascript">
function a(){
var aFrame = parent.document.frames("a");
//var aId = aFrame.document.getElementById("aId").innerText;
//alert(aId);
aFrame.tree("111");
}
</script>
</head>
<body bgcolor="blue">
<div id="top" onclick="a()">top页面</div>
</body>
</html>


3、a.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.util.*" %>
<!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 type="text/javascript">
function tree(d){
alert(d);
}
</script>
</head>
<body bgcolor="red">
<div id="aId">a页面</div>
</body>
</html>


4、b.jsp

<%@ 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>
</head>
<body bgcolor="green">
<div id="b">b页面</div>
</body>
</html>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值