PDA

View Full Version : Proper Window Handling


RadarBob
11-18-2002, 08:50 PM
The key to the problem I think is properly destroying the window variable/object I create...

This first function works the first time I open the child window. Subsequent attempts fail at the line highlighted. Seems the child window was not properly disposed of when closed. Also, if I remove focus, but do not close the child window, the function works - i.e. it puts focus on the open (but heretofore covered up) window.

function openReportsWindow() {
// just focus() if already open.
if ( typeof DBReportsWindow != "undefined") {
if (DBReportsWindow.open) {
DBReportsWindow.focus();
}else{
DBReportsWindow = window.open("Reports_Entry_Page.asp","AddReports");
}
}
} // end openReportsWindow()



This code, on the popup/child window is called when clicking "finished" on the child window.

. . .
window.close();


My inclination is to set DBReportsWindow = null; but I've either not put it in the right place, or it just won't do the trick.

chrismiceli
11-18-2002, 10:28 PM
correct me if i am wrong but isn't it typeOf() like this

function openReportsWindow() {
// just focus() if already open.
if (typeof(DBReportsWindow) != "undefined") {
if (DBReportsWindow.open) {
DBReportsWindow.focus();
}else{
DBReportsWindow = window.open("Reports_Entry_Page.asp","AddReports");
}
}
} // end openReportsWindow()

<edit> and you can shorten your if statements i believe like this

function openReportsWindow() {
// just focus() if already open.
if (typeof(DBReportsWindow) != "undefined" && DBReportsWindow.open) {
DBReportsWindow.focus();
}else{
DBReportsWindow = window.open("Reports_Entry_Page.asp","AddReports");
}
}
} // end openReportsWindow()

glenngv
11-19-2002, 03:03 AM
there's no open property for window object.
you need to use closed property.

and:

typeof DBReportsWindow == typeof(DBReportsWindow) //not typeOf()

here's the correct code:

function openReportsWindow() {
// just focus() if already open.
if ( typeof DBReportsWindow != "undefined" && !DBReportsWindow.closed) {
DBReportsWindow.focus();
}else{
DBReportsWindow = window.open("Reports_Entry_Page.asp","AddReports");
}
} // end openReportsWindow()

RadarBob
11-19-2002, 01:58 PM
if ( typeof DBReportsWindow != "undefined" && !DBReportsWindow.closed)

Thanks. Works spiffy:thumbsup:

As far as parenthesis around the arguement for "typeof". One reference shows with and one without. It seems to work either way. "Typeof" is a unary operator, not a function, so I guess the parenthesis is not strictly necessary.