//父页面内容
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<!--
作者:李瑞琦
时间:2017-08-23
描述:js中window对象下open、close、opener函数的学习
-->
<script type="text/javascript">
//父页面打开子页面
function testOpen(){
window.open("MyJs09.html","son")
}
//父页面内容
function testOpen2(){
alert("我是父页面");
}
</script>
</head>
<body>
<h3>js中window对象下open、close、opener属性的学习</h3>
<hr />
<input type="button" id="" name="" value="测试打开子页面按钮" onclick="testOpen()"/>
</body>
</html>
//子页面内容
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>son</title>
<script type="text/javascript">
//倒计时关闭网页功能
function closePage(){
window.setInterval(function(){
//获取倒计时内容
var num = document.getElementById("num");
//将倒计时内容-1
num.innerHTML = num.innerHTML-1;
//判断
if (num.innerHTML==0) {
//关闭子页面
window.close();
}
},1000)
}
//子页面调用父页面的函数
function sonFunction(){
window.opener.testOpen2();
}
</script>
</head>
<body onload="closePage()">
我是子页面,页面会在<font size="10px" id="num" color="red">5</font>秒后自动关闭。
<input type="button" id="" name="" value="此按钮调用父页面的函数" onclick="sonFunction()" />
</body>
</html>
window对象下open、close、opener函数的使用
最新推荐文章于 2025-05-18 10:59:33 发布