How can I close a child window from outside that window ?
| SitePoint Sponsor |


How can I close a child window from outside that window ?





I suck with Javascript, But I believe you would have something like this
PARENT WINDOW :
_child = window.open();
Then, to close the child window, just use _child.close();
Eric Coleman
We're consentratin' on fallin' apart
We were contenders, now throwin' the fight
I just wanna believe, I just wanna believe in us
Best way is to make sure that you have assigned a variable name to the new window, and enact the close() method on that variable
var myWin = window.open('page.htm','','');
myWin.close();





Sorta beat your post by ohh, say and HOUR! lol ;P
Eric Coleman
We're consentratin' on fallin' apart
We were contenders, now throwin' the fight
I just wanna believe, I just wanna believe in us
True, but noticed I said "Best way". What if you had to open more than one popup and close them selectively, or wanted to open a new document in the existing popup. In both cases '_child' will not work.Originally posted by Zaire
Sorta beat your post by ohh, say and HOUR! lol ;P![]()





Hrm, your code looks no different than mine..
Eric Coleman
We're consentratin' on fallin' apart
We were contenders, now throwin' the fight
I just wanna believe, I just wanna believe in us
The difference is that I defined an object variable to reference the window, whereas you used the built-in target object of '_child' to reference the window.
Bookmarks