Jump to content
  • Advertisement

Archived

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

Sander

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.

If you intended to correct an error in the post then please contact us.

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

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

Share this post


Link to post
Share on other sites
Advertisement
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 one

var callbackCnt=0;
function childCallback(){
callbackCnt++;
if(callbackCnt>=2)
setTimeout("self.close();",100);
return self.opener;
}

//In pupop two and three

var mainWin=self.opener.childCallback();
//...

mainWin.location.reload()


"Stop trying to hit me and hit me!"

Share this post


Link to post
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
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

Share this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!