I’ve been searching for an answer to my problem—with no luck so far.
Here’s my code:
var oNewWindow = window.open(sLink,'_blank');
oNewWindow.addEventListener('load',function() { alert('Page loaded'); }, false);
When the popup window/tab opens the handler is called, but if I browse inside the popup window, the handler is never called. Why? And is there a way to make it work?
The base idea is that user opens a popup window and then starts browsing in the popup, while the code in parent window continues working and monitoring what is happening in the popup. The popup page is the page on the same domain.
After loading the popup for the first time, I attached an onunload handler to it, which would call the handler in the parent window and then the timer would start. Then the parent window’s script would work with the contents of the popup. However, the problem comes with lag, if the timer runs out and the old page inside popup is still there, I get incorrect data and my whole script stops. I am unable to attach another onunload handler after that.
The onload handler is set for the window as the whole, not a document within the window, so why isn’t the handler called?
Also, my script is run with the help of GreaseMonkey. I don’t need this to be cross-browser since I only work with Firefox.
Once the user navigates away from that original page, the opened window no longer has the
loadevent applied by the opening window, which is why that alert does not fire again.One approach you could use is to have a page that wraps the desired url within an
iframe(www.mypage.com/myframe?url=someurl.com)so that the page within the child window does not change, but the contents of theiframechange. From here you can tell thewindow.openerwhat is going on from within theiframe.