Lets say I have a javascript popup window (opened using var popup = window.open()), that is pointing to the same domain.
How can I detect each time a page is loaded from the page that opened the popup (eg. after a link is clicked on or a form is submitted) o I can check if the user performed an action? Bonus points if I can get the url and response code for the page (that is loaded in the popup).
I'd also like to note I would not like to rely on the loaded page within the popup to provide information (by firing events).
Related
Hard to come up with a title, my apologizes.
Problem is this: Since modern web-browsers disable pop-up windows I am in need of a work-around.
When a visitor comes to the website they are prompt to press a button. Once the button is pressed a pop-up window is launched with the following code:
w = window.open('/audio/audioplayer.php?id='+audioId, 'audioplayer', params);
Now that the pop-up is open I would like when the visitor views other pages the pop-up is loaded with specific information based on whatever page they are on.
I am not sure if this is possible or how I can do this (check if the pop-up window is open, and if it is load the information, and if its not re-display the button)
I don't think it is possible to detect where the popup is open of not.
Have you thought about using a dialog? Rather than a popup?
window.open returns a windowObjectReference - this is the only way you can talk to the popup window. In particular, you can tell if that window is closed with the windowObjectReference.closed attribute. And the popup window has a window.opener attribute that references the parent window back. You can use both to communicate.
However, it seems you want to keep this communication between page loads. You have a few options:
Try to keep the link between windows as long as possible. The problem is that when the parent window reloads, all the javascript variables reset and there's no way to recover the reference to the popup - unless the popup sets it using window.opener. This link shows this approach and also another one with frames.You could consider it either ugly or clever. But it's not perfect. (You can't do anything if the user opens a page in a new link)
Communicate with the server using ajax from both main pages and the popup page. When a top level page wants to send a message to the popup, they start an XMLHttpRequest to your server which notifies a script which leaves a message in a "queue". The popup page regularly polls/long-polls the server with XHR too (or server sent events, my personal favorite) and updates its own contents accordingly.This might be a bit more complex/expensive than you'd like but it's also the safest solution.
Don't use popups, like the other answer suggested. A div with position: fixed could get you a similar result, and might save you from that method of communication between windows, however it also leads to having one dialog per page, so you need to ask the server if another instance of the dialog is running. Not quite sure if other methods of sync are viable for this (localstorage?)
I use a popup window for edit operations using the Kendoui framework.
When a session times out while the popup is open the login page will load inside of the popup window.
I would like to add js in the forms redirect page and check if it is being loaded inside a popup window and if so redirect and close the window.
Is there a way to determine if a page is loaded inside of a popup and if so how can I get a handle to it?
Thanks
Usually the page is not redirected to the login page until you click button or do something.
We had the same problem and we solved it using Ajax call for our popup.
So we had some button on the popup and we read the response from the server. If the session is already expired you will have the wrong response code (not 200 definitely). You can read and interpret it and in your JS close popup window and do redirect to the login page like:
window.location = login_url
I have a problem with js popup window.
I open a popup and try to access its elements in another page page, no success, and I don't want to reload the popup source, I simply want access a element of the opened popup
Ex -
1st page - opened popup with html5 music player
2nd page - need to pause the music when user click on button on main page
1st page
var popup = window.open("test.html","mypopup","width=500,height=300");
2nd page I want to access mypopup windows elements without reloading the popup
I only need the way how to access opened popup elements without interrupting its sources using JS or JQuery
Same origin (domain, port and protocol)?
Plain JS:
from page1
var popup = window.open("test.html","mypopup","width=500,height=300");
popup.document.getElementById("player").someFunction();
from page 2
var popup = window.open('','mypopup');
// now popup is known again
popup.document.getElementById("player").someFunction();
I am embedding a dynamic webpage in a popup. Currently its working and every time popup is loaded the webpage is loaded again, thus me losing the work i did on the webpage in popup. Though its fine, but i want that webpage remain loaded in background and i just show it in popup on click. to do this i copied complete code from my pop up page(script+html) to background.html. Now how should i access the page completely in popup and show directly(i want to show html also-from background page)
Thanks
Popups live in the same process (the extension process) as the background page, and one page can get the DOM Window of the other. A popup gets the background page by calling chrome.extension.getBackgroundPage(). So every time you open the popup, just read and write to some variable on the background page, for example chrome.extension.getBackgroundPage().enteredData = "value";.
Alternately, you can use HTML5 localStorage to store variables even after the browser is shut down; e.g. localStorage['enteredData'] = "value".
I have a question on javascript window management.
My application opens an iframe which displays a link. Clicking on the link, opens a popup window, in which I enter my login credentials. My intention is to close the popup window after the login credentials are entered. And this I have been able to achieve using a JS call to self.close().
There after my server side script does some more processing and would like to display the results back in the iframe. This is where things break for me.
The overall flow is as follows:
Iframe Displays a Link --> Clicking on the Link Pops up a window --> Popup Window closes after credentials are entered --> I see my original iframe now (How do I display the contents back in the iframe). Here is the code snippet that closes the popup.
5
6 self.close();
7
The parent of the popup is the iframe. If I modify the above script to give the focus back to its parent, which in my case will be the iframe, will that suffice? Or am I issing something here?
you can access the iframe from your popup by using opener. for example this will reload your iframe:
<script type="text/javascript">
opener.location.href = "htp://mypage.com/myiframe.php";
</script>
you just have to add the right parameters to show what you want to. (of course you have to do this before your self.close();)