Close a popup window

D

David W. Simmonds

I have a popup window appear when a user clicks on a hyperlink in a
datalist. I do it like this:

dr[8] = "javascript:mywindow=window.open(" +
"\"GameStats.aspx?Date="+dr[0] + "&Away="+dr[1] + "&Home="+dr[4] + "\"" +
",\"GamesStats\",\"toolbar=no,location=no,directories=no,menubar=no,resizabl
e=yes,scrollbars=yes,width=640,height=300\");mywindow.focus();";

dr[8] is a DataRow item that is added to a DataTable that becomes the
DataSource of the DataGrid.

Is there a way to have that window close when the form that caused it to
appear closes?
 
D

Dan Brussee

Using the onunload event of the window object.

window.onunload = ClosePop;
function ClosePop() {
if (mywindow != null) {
if (mywindow != "undefined") {
mywindow.close();
}
}
}

Also, before popping up your window, call ClosePop(). This will assure
that you only have one popup open... assuming you always call your
popup mywindow.
 
D

David W. Simmonds

That works great! Thanks.

Dan Brussee said:
Using the onunload event of the window object.

window.onunload = ClosePop;
function ClosePop() {
if (mywindow != null) {
if (mywindow != "undefined") {
mywindow.close();
}
}
}

Also, before popping up your window, call ClosePop(). This will assure
that you only have one popup open... assuming you always call your
popup mywindow.


I have a popup window appear when a user clicks on a hyperlink in a
datalist. I do it like this:

dr[8] = "javascript:mywindow=window.open(" +
"\"GameStats.aspx?Date="+dr[0] + "&Away="+dr[1] + "&Home="+dr[4] + "\"" +
",\"GamesStats\",\"toolbar=no,location=no,directories=no,menubar=no,resizab
l
e=yes,scrollbars=yes,width=640,height=300\");mywindow.focus();";

dr[8] is a DataRow item that is added to a DataTable that becomes the
DataSource of the DataGrid.

Is there a way to have that window close when the form that caused it to
appear closes?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top