Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by fpoyavo
at 2024-07-15 14:55:13
Point:500 Replies:6 POST_ID:828985USER_ID:11886
Topic:
PHP Scripting Language;;JavaScript
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.
Thanks.
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.
Thanks.
Accepted Solution
Expert: Gary replied at 2024-07-16 11:11:35
500 points EXCELLENT
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)
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="//code.jquery.com/jquery-latest.min.js"></script><script>var childwindow$("a").click(function(){ childwindow = window.open($(this).attr("href"), '', 'height=200,width=400'); childwindow .onbeforeunload = function () { alert("Child Closed") }})</script> 1:2:3:4:5:6:7:8:9:10:11:12:13:
Expert: Ray Paseur replied at 2024-07-16 06:16:53
See if this helps you understand the issues.
http://msdn.microsoft.com/en-us/library/ms536973%28VS.85%29.aspx
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.
http://msdn.microsoft.com/en-us/library/ms536973%28VS.85%29.aspx
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.
Expert: duncanb7 replied at 2024-07-15 21:00:42
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
yahoo.com 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
Duncan
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
yahoo.com 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
Duncan
<?php?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Pop window javascript</title><script type="text/javascript" >function init(){str="menubar=1,scrollbars=yes,resizable=1,width=450,height=600";win=window.open("http://yahoo.com/us",'_blank',str);//console.log("mess",win.closed);pollTimer=window.setInterval(function(){if (win.closed== true) { // !== is required for compatibility with Opera window.clearInterval(pollTimer); document.getElementById("mess").innerHTML="Close Pop Window"; }},5000);}</script></head><body onload="javascript:init();"><div id="mess">Open Pop Window</div></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:
Expert: Ray Paseur replied at 2024-07-15 17:39:03
...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. Author: fpoyavo replied at 2024-07-15 16:41:05
Hi,
I am trying exactly what I wrote before. The server code and client code can communicate as you know.
Thanks.
I am trying exactly what I wrote before. The server code and client code can communicate as you know.
Thanks.
Expert: Randy Poole replied at 2024-07-15 15:02:18
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?