子母視窗關來關去

1.母視窗可關閉子視窗
2.子視窗可關閉母視窗
3.不是利用強迫對話方塊函數(window.showModalDialog 或 window.showModelessDialog()),而讓子視窗固定在上方。


-------------------------------------------
a.htm(母視窗)
-------------------------------------------
<!--load時沒有指定本身視窗名稱,那母視窗被關閉時會出現詢問訊息-->
<BODY onload="mname()" onclick="onTop()">
<SCRIPT Language=JavaScript>
var newwin = null;
function mname(){self.opener='aa';}
function onTop() {
if (newwin != null && newwin.open)
{newwin.focus();}
}
function opwin(){
newwin=window.open('b.htm','nw','width=400,height=100,resizable=yes,scrollbars=yes,status=0');
newwin.moveTo(200,10);
}

function closeb() {
if (newwin != null && newwin.open) newwin.close();newwin=null;
}
</script>
<p align=center>I am Mother window!!<br>
<p align=center>
<input type=button onclick="opwin()" value="開啟子視窗">
<input type=button onclick="closeb()" value="關閉子視窗">
</BODY>


------------------------------------------
b.htm(子視窗)
------------------------------------------
<BODY bgcolor="#FFCC00" topmargin=20>
<script language=javascript>
function CloseWin(){
window.close();
}
function CloseWin1(){
opener.window.close();
}
function Mreload(){
opener.window.location.reload();
}
</script>
<p align=center>I am Children window!!<br>
<input type=button onclick="Mreload()" value="母視窗重整">
<input type=button onclick="CloseWin1()" value="關閉母視窗">
<input type=button onclick="CloseWin();CloseWin1()" value="關閉子母視窗">
</BODY>

沒有留言: