PHP + JavaScript: Execute and Reload - part 2

Started by
4 comments, last by Sander 20 years, 3 months ago
Hello again, My question is roughly similar to the last one I posted here, but this time I need a different solution. I am writing a database driven QA system with PHP (and some &#106avascript). The user goes to a certain page (PHP driven ofcourse) that shows an overview of a certain table. Next, the user clicks on a buton to add a new entry. A popup opens, he enters some data, clicks OK and the data is added to the table. The popup closes and the main page is reloaded. Pretty easy. Something like this in the popup:

self.opener.location.reload()
self.close()
 
Now comes the harder part: This time, the user has to enter some more data, so the initial popup opens up another two popups. after that, the initial popup closes. These two new popups need to do the same as in the first scenario. That is, upon completion they must reload the main window and then close themselves. But there is a problem. The initial popup is already closed so calling something like:

self.opener.opener.location.reload()
 
will just lead me into the void as self.opener doesn''t exist anymore. Is there anyway to give my main window some kind of name or handle so that I can simply do the same for all popups, no matter who created the popups? Something like:

window[''myMainWindow''].location.reload()
self.close()

or

myMainWindow.location.reload()
self.close()
 
Any way to accomplish this? Sander Maréchal [Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Advertisement
Nobody? Please?

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

I would pass the opener reference of the first popup to the two new ones by making them call a function in their opener (the first popup) that returns its opener and then closes itself if it has been called twice.
Example:
//In popup onevar callbackCnt=0;function childCallback(){   callbackCnt++;   if(callbackCnt>=2)      setTimeout("self.close();",100);   return self.opener;}//In pupop two and threevar mainWin=self.opener.childCallback();//...mainWin.location.reload()


"Stop trying to hit me and hit me!"
Emil Johansen- SMMOG AI designerhttp://smmog.com
Thanks for the tip, but it won''t work since self.opener.childCallback() won''t exist anymore (self.opener doesn''t exist at all anymore for popup 2 & 3).

I have got it figured though Here''s how:
function popup(url){  newPopup = window.open(url)  if (self.name != ''mainpage'')  {    newPopup.opener = self.opener  }}function killPopup(){  self.opener.location.reload()  self.close()} 

recursion will make sure that self.opener will always point to the main window, and not the actual opener. Works like a charm!

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

quote:but it won''t work since self.opener.childCallback() won''t exist anymore

I am afraid you have misunderstood the code. childCallback is called once by each of the two popups. When the second call is complete, the first popup closes. childCallback will net be called again.
Your method uses the same priciple only prettier - that is if all browsers support overriding of the opener variable.
Emil Johansen- SMMOG AI designerhttp://smmog.com
Thanks for the explanation Thank god I don''t have to worry about browser support. This is an intranet-site and everybody uses eighter IE 5.5 or IE 6 Lucky me!

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement