在frameset上可以在页面上面划分出多个区域,这是一般管理系统的主要布局方式,但是再一个页面可以调用另外一个页面的属性和方法。页面上可以包含iframe嵌套。
祖先页面:
<%@ 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">
-->
<script type="text/javascript">
function top1(){
alert("祖先方法");
}
</script>
</head>
<frameset cols="50%,50%">
<frame src="html/1.html" name="c1"></frame>
<frame src="html/2.html" name="c2"></frame>
</frameset>
</html>
儿子1页面 1.html:
<!DOCTYPE html>
<html>
<head>
<title>1.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
$().ready(function(){
alert("左边加载完...");
alert($('span',window.parent.frames["c2"].document).text());
});
function xd1(){
alert("我是左边的方法");
}
</script>
</head>
<body>
11111111111111111111<p/>
<button οnclick='window.parent.frames["c2"].xd2();'>调右边的方法</button>
<button οnclick='window.parent.frames["c2"].frames["c21"].sunzi();'>调右边的儿子方法</button>
</body>
</html>
儿子二页面 2.html:
<!DOCTYPE html>
<html>
<head>
<title>2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
$().ready(function(){
alert("右边加载完...");
});
function xd2(){
alert("我是右边的方法");
}
</script>
</head>
<body>
<span>我是右边的属性</span>
2222222222222222222222
<div>
<iframe src="3.html" name="c21"></iframe>
</div>
</body>
</html>
二儿子的儿子页面 3.html:
<!DOCTYPE html>
<html>
<head>
<title>3.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function sunzi(){
alert("孙子方法");
}
</script>
</head>
<body>
我是页面2的儿子<p/>
<button οnclick="window.parent.xd2();">父亲按钮</button>
<button οnclick='window.parent.parent.frames["c1"].xd1();'>爷爷按钮</button>
<button οnclick="window.top.top1();">祖先按钮</button>
</body>
</html>
frameset是最早的祖先页面。frame是祖先页面的子页面,原理和iframe是一样的。无论其方法调用还是祖父元素和兄弟页面之间调用都和iframe一样的。
参考链接:
http://747017186.iteye.com/blog/1985110