php javascript new window

Hi Experts,

I have simple php page with just loop in it. What I need to do is to open popup window [not my url .. can be anything meaning I just have url I don't create that page] as a child window from php page then in that loop to wait until this child window is closed and continue my loop.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy PooleCommented:
php is executed on the server and the output is pushed to the client so this is not possible. What are you trying to accomplish?
fpoyavoAuthor Commented:

I am trying exactly what I wrote before. The server code and client code can communicate as you know.

Ray PaseurCommented:
...wait until this child window is closed and continue my loop
I don't know of any "window closed" signal that comes from the client to the server, and there is nothing I have ever seen that allows the server to wait for the client, other than the HTTP protocol for client/server communications.  The problem with trying to get this information goes to the essential nature of the HTTP client/server protocol.  Clients make requests, and servers make responses.  The request is atomic, complete and stateless.  The server response is based solely on the client request, is complete and usually instantaneous.  And that's it - nothing more.  There is no "back-and-forth" at all -- just requests and responses.  That said, if you want to show us a web site that does what you're describing, I'll be glad to examine it and tell you how it works.  Or if you want to give us a concrete example with more details and less theory we might be able to suggest a common design pattern.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

You might just need javascript code only as follows for reference only not fully tested.
If you still want to include javascript code in php, you need to
put it by echo , for  exampel,  <?php echo "<script type.....function init()......</script>...."; ?>
Probably, your issue will be solved just by javascript.
When the html page is running or on loading, it will run init() function in whcih will open in pop window and the timer by window.setInterval will
check the pop window is closed or not for 5 seconds. If closed, it will
display message "Close Pop Window" at div tag with id of "mess"

Hope understand your question completely.If not, please point it out
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Pop window javascript</title>
<script type="text/javascript" >
function init(){

if (win.closed== true) { // !== is required for compatibility with Opera
        document.getElementById("mess").innerHTML="Close Pop Window";
<body onload="javascript:init();">
<div id="mess">Open Pop Window</div>

Open in new window

Ray PaseurCommented:
See if this helps you understand the issues.

jQuery had an unload event handler a long time ago, but it was deprecated at jQuery 1.8, probably because it behaved unpredictably and fired on a number of counter-intuitive events.  For example, it would fire when the client followed a link or gave focus to a different window.  There is a beforeunload event handler, but a careful reading of the literature indicates that has numerous problems, too (quirky cross browser implementation, fails on iPad, etc).

Executive summary: You cannot reliably detect or manipulate (human) client behavior, unless the client makes an HTTP request.  Closing a window does not trigger an HTTP request.  In some browsers, closing a window may trigger an event handler, but this event handler is shared by many other events.  So this design sounds like a recipe for confusion.
If the child window was loading a url that you have control over then you can capture when the child window is closed.
But if the url is a domain you do not control then it is not possible due to cross domain scripting security

Sample for same url (using jquery)

<a href="#">Click to open child window</a>

<script type="text/javascript" src="//"></script>

var childwindow 
	childwindow =$(this).attr("href"), '', 'height=200,width=400');
	childwindow .onbeforeunload = function () {
		alert("Child Closed")

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.