I have a script that opens a popup in the same host. The popup is opened with window.open(url,name,settings)
without assigning it to a variable.
I can't change the function that opens the popup and neither the code of the popup. But I can add extra Javascript code in the opener's load/ready event.
What I need is to know, from the opener, when the popup is open.
I know the name of the window, so if it's already open I can check it with:
var openedWin = window.open('', 'Selection');
But the problem is that when the window is not open, it tries to create a new window.
How can I implement a listener or something that let me check when a named popup window is opened?
Thank you!
I can only think of one way to do this, and it's ugly : Monkeypatch window.open
in the opener's load/ready event you said you have access to:
var original = window.open;
window.open = function(url, windowName, windowFeatures) {
// Chain to the original
var wnd = original.call(window, url, windowName, windowFeatures);
if (windowName === "Selection") {
// Do whatever it is you want to do with `wnd`
}
return wnd;
};
If there's any other solution, use it; but if there isn't (and I don't think there is), this should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.