Click to See Complete Forum and Search --> : Window won't window.close()


briandunning
12-02-2003, 02:15 PM
I have a popup window that submits a forum to the main window, which works just fine. But I can't figure out how to get the popup window to close itself after submitting the form.

In the popup, I have:

<script>
window.name="pop";
</script>

The main window then reloads with the form results (works great) and I'm trying to get that to close the popup window, which doesn't work:

<script>
window.close("pop");
</script>

The little window named "pop" remains. What am I doing wrong?

fredmv
12-02-2003, 02:17 PM
The close method doesn't accept any arguments, but rather, the new window has a close method. All you need to do is call it:pop.close();

briandunning
12-02-2003, 02:24 PM
Thanks for such a fast reply! Wow, I did not know that, thank you.

Wouldn't you know it, still doesn't work. Here I've copied & pasted the exact code from my "main" window, note that I even tried doubling up by including the onLoad thing in the body tag:

<body onLoad="pop.close()">
<script type="text/javascript" language="javascript">
window.name="main";
pop.close();
</script>

How can this not work? The window "pop" remains open. Is it because the window "main" already existed?

fredmv
12-02-2003, 02:30 PM
Interesting. Does this example help at all?<a href="http://www.google.com/" onclick="w=window.open(this.href, 'child', 'height=300,width=300');return false;">Open</a> |
<a href="#" onclick="if(typeof w!='undefined')w.close();">Close</a>

briandunning
12-02-2003, 02:36 PM
IE's little script error thingie is telling me that 'pop' is undefined. Does that help?

The "pop" window contains the following code:

<script type="text/javascript" language="javascript">
window.name="pop";
</script>

fredmv
12-02-2003, 02:41 PM
In my previous example, pop doesn't refer to the name of the window, but refers to a reference to the window. In the new window, you don't even need to name it, as long as the parent window assigns a reference to the new winodw in the variable you should be all set. Here's some code that might help you understand this more:// Create a new window and store a reference to it in the "w" variable.
var w = window.open('foo.html', 'foo', 'height=500,width=500');

// Now, we can close it by simply calling it's close method.
w.close();

briandunning
12-02-2003, 02:47 PM
Oh, I understand. (light bulb goes on)

I guess I'm still missing where & how you call that w.close() though. If my "main" window is going to be reloaded by the targeted form from "pop", then when does the variable "w" get a chance to be loaded? That w=window.open was two pages ago.