View Full Version : Closing other windows


plltyeah
01-01-2006, 10:57 PM
I know that theres the javascript <a href="javascript: self.close()"> but is there a way to reference a specific window so that you click on a link and it closes a different page?

Thanks!

pb&j
01-02-2006, 07:10 AM
i am really bad at javascript but try this...

<a href="javascript: MyExample.close();">

just replace that ^ part with the "name" of the window you created/opened.

if the window was not created and named, then you may be out of luck.

plltyeah
01-04-2006, 05:38 AM
and uh... how do you name a window?

pb&j
01-04-2006, 06:26 AM
when you create a window, you can assign a name value to it...

window.open("URL","Name","parameters");

Douglas
01-04-2006, 06:12 PM
If you want to close the window that you just clicked a link to a popup from (do you understand?), you can use this, name it popup.html:


<script language="JavaScript" type="text/javascript">
<!--;
function close_other_win() {
opener.close();
}
function change_other_win(url) {
opener.location=url;
}
//-->
</script>

<a href="javascript:close_other_win();">Close other window</a><br />
<a href="javascript:change_other_win('http://www.example.org/');">Change location of other window.</a>


name this thing.html:


<script>
window.open('popup.html','','width=500,height=500' );
</script>


Make sure they are in the same directory, they don't need to be online to work either :)

plltyeah
01-09-2006, 01:07 AM
I tried that and it didn't work. I open thing.html and popup.html comes up, but neither link does anything. Really what I want to do is just change the location of the original page and close the popup.

Douglas
01-09-2006, 06:04 PM
Well, that seems to work on my computer, if you want it to close and redirect (put this in the popup):


<script language="JavaScript" type="text/javascript">
<!--;
function do(redir) {
opener.location=redir;
window.close();
}
//-->
</script>

<a href="javascript:do('http://www.example.com');">Close and redirect.</a>


What browser do you have?

plltyeah
01-10-2006, 02:27 PM
Actually the first one is working I don't know what the problem was but it's working now so thanks!

Douglas
01-10-2006, 05:49 PM
Okay, no problem, good luck ;)