關(guān)閉彈出的窗口時,同時刷新父窗口,一般用來使父窗口獲取最新的數(shù)據(jù)。
本實(shí)例主要應(yīng)用 window.open()語句打開新窗口,并在新窗口中應(yīng)用 opener 屬性,該屬性返回一個引用,用于指定打開本窗口的窗口對象。
語法:
功能:返回的是一個窗口對象。opener 屬性與打開該窗口的父窗口相聯(lián)系,當(dāng)訪問子窗口中 opener 屬性時,返回的是父窗口,通過該屬性,可以使用父窗口對象中的方法和屬性。
reload()方法是用來刷新指定窗口的。
1.要彈出的窗口,并且實(shí)現(xiàn)關(guān)閉刷新父窗口的頁面 new.html
<html>
<head>
<meta charset="utf-8" />
<title>彈出的窗口</title>
<style type="text/css">
body{
background-image:url(new.jpg);
background-repeat:no-repeat;
}
</style>
<script>
function pp()
{
alert(window.opener);
window.opener.location.reload();
window.close();
}
</script>
</head>
<body>
<input type = "button" value = "關(guān)閉" onClick="pp();"/>
</body>
</html>
2.主窗口 index.html
<html>
<head>
<meta charset="utf-8" />
<script type="text/jscript" language="javascript">
window.open("new.html","new","height=280,width=800,top=10,left=20,resizable=no, location=no",false);
</script>
<style type="text/css">
p{
font-size:24px;
color:#F00;
}
</style>
</head>
<body>
<p>網(wǎng)站首頁</p>
</body>
</html>