homepage Welcome to WebmasterWorld Guest from 54.242.126.9
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript button to close a diferent window?
Can anyone tell me how to do this.
kapow

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 34 posted 1:54 pm on Jan 21, 2002 (gmt 0)

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.

 

joshie76

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 34 posted 2:49 pm on Jan 21, 2002 (gmt 0)

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>

kapow

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 34 posted 3:14 pm on Jan 21, 2002 (gmt 0)

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).

joshie76

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 34 posted 3:25 pm on Jan 21, 2002 (gmt 0)

<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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved