Entry
How can I capture onLoad event of Parent window in its Child Window using Javascript
May 19th, 2001 20:30
Colin Fraser, Shailesh Urhekar,
You cannot.
the onLoad event of the parent window has already fired before you can
access the child window, that is why it is called parent and child
windows. If you want to work on the parent window from the child, try :
<script langauge="JavaScript"><!--
function closeParent() (
opener.close(); }
//-->
</script>
<body onLoad="closeparent()">
in the child window
In the parent window you will have to ensure that the opener has been
defined for browsers who do not use "opener"
<script language="JavaScript"><!--
function openChild() {
myChild=open('',window,'resizable=no,width=200,height=200');
myChild.location.href ='apage.html';
if (myChild.opener == null) myChild.opener = self;
}
//--></script>
call this function from a button.
<form>
<input type="button" onClick="openChild()">
</form>
However, that this may prompt the user for confirmation before closing
the window.
Also in the parent
<script> <!--//
function myonUnloadEvent() {
//do whatever here
}
//-->
</script>
<body onUnload="myunloadEvent()">
Good luck