Hal said:
Thanks for the reply.
The variable is assigned (and the window opened) in this script, which
is only executed when the user clicks a link on the parent page. It
is possible the user never clicks the link.
<script type="text/javascript">
You should define the window object reference explicitly as a global
variable right here like this:
var g_win1;
function MM_openBrWindow(theURL,winName,features)
{
g_win1 = window.open(theURL,winName,features);
}
</script>
The body tag of the parent page looks like this:
<body OnUnload = "javascript:HF_CloseAllChildren();">
The "javascript:" part is unneeded and irrelevant. As long as you define
the default script language in the <head> part, then you never need to
add "javascript:" anywhere else.
Defining default scripting language in HTML 4.01:
http://www.w3.org/TR/html401/interact/scripts.html#default-script
<head>
....
<meta http-equiv="Content-Script-Type" content="text/javascript">
....
Which executes this script:
<script type="text/javascript">
function HF_CloseAllChildren() {
if ((g_win1) && !(g_win1.closed))
g_win1.close();
}
</script>
<script type="text/javascript">
function HF_CloseAllChildren()
{
if (g_win1 != null && !g_win1.closed)
{ if(g_win1.close) {g_win1.close();};
}
Note that recent Mozilla-based browsers will not honor g_win1.close() if
a particular user pref prevents it from working.
user_pref("dom.allow_scripts_to_close_windows", false);
You may also get a similar behavior in Opera 7.x. Note that you are
trying to close automatically a window without the user's explicit will.
The problem is that when the user has not opened the child window,
she/he gets an error message saying that g_win1 is undefined.
And that is how a consensus of browser manufacturers (MSIE, Mozilla,
Opera, etc) agree on: a script should not be able to close a window
which was not opened by javascript. Would you imagine a tv content
provider (CBS, NBC or ABC) being able to close your tv set?
I
thought the line:
if ((g_win1) && !(g_win1.closed))
would evaluate to false if g_win is undefined and would not throw an
error. Is there any way I can accomplish this? I know that I can use
code to open the window just to close it, but that seems very clumsy
to me, especially since there are up to 7 child windows
7 different child windows or 7 different documents into the same
reusable, recyclable secondary window: there is a huge difference of
meaning and consequently usability repercussion here.
that can be
opened from this parent page. Any ideas?
Hal
It would have been easier for everyone from the beginning to mention an
url.
DU