Close a popup window

  • Thread starter Thread starter David W. Simmonds
  • Start date Start date
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?
 
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.
 
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?
 
Back
Top