#### Archived

This topic is now archived and is closed to further replies.

# PHP + JavaScript: Execute and Reload - part 2

This topic is 5330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 javascript). 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

self.close()

Any way to accomplish this? Sander Maréchal

Sander Maréchal

##### Share on other sites
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!"

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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

1. 1
2. 2
3. 3
4. 4
frob
12
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632172
• Total Posts
3004562

×