PDA

View Full Version : Popup Window doesn't after 1st time


RadarBob
10-23-2002, 06:03 PM
Has anyone seen this phenomenon?

I have two buttons, each of which spawns a child window. Here's the scenario:

Parent page displays
click on one of the buttons
child window opens normally
child window functions normally
click "finished"button, window closes
back on parent page, click that button again.
I get an error message on the browser status line "error on page"
The parent page seems to function normally
AAARRRGGG!


I can also do this exact same senario for the second button/window opening. In other words, the buttons work normally, but only the first time, only once.

If I refresh the mother page I can trigger the child page - but again, only once

Let me say that at one time this was all working perfectly! I could open/close the child window via the button all day long and it worked! But I must have sneezed when I was later editing the mother page, 'cause I don't know what the heck is going on!!! Maybe I deleted a return statement. Maybe I need to set the window object to null... I'm just guessing here..

Here is the relevant code on the mother page:

function openKeywordWindow (theform) {
if (typeof DBKeywordsWindow != "undefined") {
DBKeywordsWindow.focus();
}else{
DBKeywordsWindow = window.open("Keyword_Entry_Page.asp","AddKeywords",
"toolbar=no,menubar=no,location=no, directories=no,
width=500, height=400, resizable=yes, scrollbars=yes");
}
} // end openKeywordWindow()


function addReports() {
// just focus() if already open.
if ( typeof DBReportsWindow != "undefined") {
DBReportsWindow.focus();
}else{
DBReportsWindow = window.open("Reports_Entry_Page.asp","AddReports",
"toolbar=no,menubar=yes,location=no,directories=no,
width=700,height=400,resizable=yes,scrollbars=yes,
left=20,top=20,screenX=20,screenY=20");
}
// "left" & "top" work in Internet Explorer.
} // end openReportsWindow()

. . .

<input type="button" name="addKeywords" value=" Edit Keywords "
onclick="openKeywordWindow(document.DBForm)">

<input type="Button" name="NewReport" value=" Edit Reports "
onclick="addReports();">



Here is the code on the child pages that closes things out:

<input type="button" name="closewindow" id="closewindowIDEE"
value=" Finished " onclick="javascript: window.close()">


Below, "finished" passes data back to the parent page - that works.

function finished(theform) {
var e = theform.newList.options;
// handle that pesky "<-- empty -->" marker
if (e[0].value=='00') e[0]=null;

// clean out then rebuild the original keyword list in the parent window
window.opener.clearKeywordList();

// addKeyword function is on the parent page
for (var i=0; i <= e.length-1; i++) {
window.opener.addKeyword(e.options[i].text, e.options[i].text);
}

window.close();
} // finished()

. . .

<input type="button" name="closewindow" value=" Finished "
onclick="finished(this.form)">

Roelf
10-23-2002, 06:58 PM
try alerting the value of (typeof DBKeywordsWindow) after closing the popup window, my best guess is that its not undefined. Of course the first time its undefined, but after closing it, its probably not anymore. You test for it to be undefined, meybe you should alter that test

RadarBob
10-29-2002, 08:34 PM
OK, I have it narrowed down to the fact that the child window closes but it's window object still exists. This causes the following (called when the parent page form is SUBMITted) statement to fail:

function closePopups() {
var allPopupsClosed = new Boolean(true);

if (typeof DBKeywordsWindow != "undefined") {
DBKeywordsWindow.focus();
allPopupsClosed = false;
}

if (typeof DBReportsWindow != "undefined") {
DBReportsWindow.focus();
allPopupsClosed = false;
}
return allPopupsClosed;
} // checkPopups()



Which, in turn, causes all my data field validation code to not execute... a regular domino effect!

The statement fails because the window object is still defined and the code attempts to focus() on a closed window (I suppose).

If I change the statement to check for DBKeywordsWindow.closed then that doesn't work if the child window was never created in the first place.

So my question is
How do I properly dispose of the window object when I close the window? OK, don't tell me to set it to null.. The question is where in all the code to do it?

glenngv
10-30-2002, 01:24 AM
if (typeof DBKeywordsWindow != "undefined" && !DBKeywordsWindow.closed)