Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window does not execute

Status
Not open for further replies.
Aug 4, 2003
12
0
0
US
I am trying to open a window and run a query within it. The window is supposed to set certain calling window variables and the main window needs to execute some code after the called window is closed. But as soon as the window opened with the following:

var szURL = "calcvalues.cfm?valueA=" + value1 +'&valueB=' +value2;
var x = window.open(szURL, 'ABC', 'width=50,height=50,alwaysRaised');

the main window starts executing next statments while the called window is still executing. I need to wait until the called window finishes. I tried to put the while loop to check if window is closed but that only hogs the system and called window does not even get time to execute.

Thanks,
 
Try using timeouts as such:

Code:
var readyToContinue = false;
var waitUntilReady;

function whatever()
{
 //your code
 var szURL = "calcvalues.cfm?valueA=" + value1 +'&valueB=' +value2;
                var x = window.open(szURL, 'ABC', 'width=50,height=50,alwaysRaised');

 //new code
 
 checkReadyToMoveOn();
 
 //rest of your code
 ...
}

function checkReadyToMoveOn()
{
 if(!readyToContinue)
  waitUntilReady = setTimeout("checkReadyToMoveOn();",100);
 else
  clearTimeout(waitUntilReady);
}

Then, in the child windows BODY tag, include as an onLoad event: opener.readyToContinue=true;

Even though this timeout stuff runs a check every 100 ms, it is MUCH slower than just using a while-loop and shouldn't hog your system's resources.

'hope this helps.

Oh yeah, in your declaration of szURL, you are mixing single quotes and double-quotes in the same statement. Careful how you do that. You may get unpredictable results.

--Dave
 
This is why the showModalDialog() method was invented. You can put a statement like this in your code:
Code:
if(window.showModalDialog(...)=="YES"){ //do somthing }

And your code will wait until the modal window closes before it continues. You set the return value from within the modal window like this:

window.returnValue="YES"


Adam
 
Ooh! I keep forgetting about that. It's new to me. Does it work in both Explorer and Navigator?

--Dave
 
Dave, thanks for the quick response and although the logic you mentioned was supposed to work fine but it did not. Somehow, the main window still executed the code with the old information in the variables. The only thing I changed was setting opener.readytocontinue flag right before the close of the called window so that I know all the statement in that window are now executed. Amazingly, if I put an alert in the checkReadyToMoveOn() function in the else part, I receive the changed value, strange is not it. The work around I found (although I do not like it) was to put the calling window code in a function and execute it from the called window.

Adam, your showModalDialog() would work only in situations where a dialog box is allowable. I am trying to execute part of code on OnChange of a form variable. Showing up a dialog box is not something desirable at that point.
Thanks for the input though.

Waseem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top