Welcome to WebmasterWorld Guest from 54.205.74.11

Forum Moderators: open

JavaScript button to close a diferent window?

Can anyone tell me how to do this.

   
1:54 pm on Jan 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can anyone tell me how to do this.

I want to provide a buton on my index page to close a popup window.

I know that usually you would put the button on the popup window but I have a need to close the popup from the index page.

2:49 pm on Jan 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Provided you name your popup window:

<script>
windowname = window.open(blahblah)
</script>

Then you can reference that window from any other page by it's name, say:

<script>
windowname.close()
</script>

3:14 pm on Jan 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Joshie76
Thats just what I needed.

What java script will say:
If the window is already open then don't open it again ?

So that I can link back to the page that opens the popup without opening it again (if you see what I mean).

3:25 pm on Jan 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script>
windowname = window.open()

function test()
{
if (windowname && !windowname.closed)
{
alert('Window is still open');
}
}
</script>

That should* tell you whether your window is still open or not... There's also some more useful info in this kind of thing in this forum:

[webmasterworld.com...]

*Handle this with a bit of care, some browsers vary in the way they handle the window objects - you'll need to do a bit of testing. Let us know if you run into any trouble. I only tested the above script in IE5.5 though you probably get the idea.

Josh

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month