08,html当前窗口,框架集元素实例,顶层窗口

(1),顶层窗口及底层窗口

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
    <style type="text/css"></style>
	<link rel="stylesheet" type="text/css" href="#">
	
</head>
<body>
	
	<input type="button" value="测试1" onclick="testFun()" />
	
</body>
<script type="text/javascript">
	
	function testFun() {
		
		// 当前窗口是否底层窗口
		if(window.parent == window.self) {
			alert("是底层窗口");
		}
		
		// 是否最顶层窗口
		if(window.top != window.self) {
			alert("不是最顶层窗口,当前窗口在一个框架中");
		} else {
			alert("是最顶层窗口");
		}
		
	}
	
</script>
</html>

(2),框架集元素子窗口调用父窗口js方法及调用兄弟窗口(注意:页面都是在同一个域)

<!--indexIframeTest.jsp页面-->
<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%
        String contextPath = request.getContextPath();
    %>
    <title>test</title>

    <script type="text/javascript">

        function testParentFun() {
            alert("这是父页面中js方法的信息提示!");
        }

    </script>

</head>
<body>

    <iframe src="<%=contextPath %>/pub/testDirectory/firTest.jsp" frameborder="1"></iframe>
    <iframe src="<%=contextPath %>/pub/testDirectory/secTest.jsp" frameborder="1"></iframe>

</body>
</html>
<!--firTest.jsp页面-->
<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%
        String contextPath = request.getContextPath();
    %>
    <title>test</title>

    <script type="text/javascript">

        // 测试调用父页面js方法
        function testParentFun() {
            window.parent.window.testParentFun();
        }

        // 测试调用同父页面下的第二个页面js方法
        function testSecFun() {

            window.parent.frames[1].window.secFunction();
        }

    </script>

</head>
<body>

    这是子页面,的第一个页面
    <input type="button" value="测试调用父页面js方法" onclick="testParentFun()" />
    <input type="button" value="测试调用同父页面下的第二个页面js方法" onclick="testSecFun()" />

</body>
</html>
<!--secTest.jsp页面-->
<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%
        String contextPath = request.getContextPath();
    %>
    <title>test</title>

    <script type="text/javascript">
        
        function secFunction() {

            var divInnerText = document.getElementById("divID_01").innerText;
            alert("这是第二个页面js方法,使用innerText获取层元素里内容="+ divInnerText);
        }
        
    </script>

</head>
<body>

    这是子页面,的第二个页面
    <div id="divID_01">
        这是层元素里的内容
    </div>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值