PDA

View Full Version : How to detect child window was closed.


NinjaTurtle
11-30-2004, 08:56 AM
Dear,

how to detect child window was closed, if child window was closed, parent win will reload, if the "add" button has been clicked the parent window will not refresh.

eg:
Parent(xyz.html)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>parent</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="JavaScript">
function OpenWin(){
popup=window.open('abc.html', 'result', 'scrollbars,resizable,width=640,height=480')

}
</script>
<body>
xyz.html<br>
<input name="xxx" type="button" value="xxx" onclick="OpenWin()">
<input type="text" name="textfield">
</body>
</html>


Child(abc.html):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script languange="javascript">
function closedetect(){
alert("are u sure u wanna close?")
window.opener.location.reload()
}

function internalrefresh(){
//alert(popup.close)
//window.opener.location.reload()
//window.close()
if (window.close){
alert("close")
}else{
alert("Add button")
}
}
</script>
<body onunload="internalrefresh()">
child<P>
<form action="abc.html" method="post" name="form1">
<input name="Add" type="submit" value="add" >
</form>
</P>
</body>
</html>

glenngv
11-30-2004, 02:19 PM
<script type="text/javascript">
var reloadParent=true;
function closedetect(){
if (reloadParent && opener && !opener.closed) opener.location.reload();
}
</script>
<body onunload="closedetect()">
<form>
...
<input name="Add" type="submit" value="add" onclick="reloadParent=false">
</form>