I have a web application that opens multiple windows. The problem that I have is that when the parent window is closed/refreshed, the child windows remain opened.
I've tried using onunload
and onbeforeunload
but none of them catches the window close event (in Chrome and Firefox).
I have an array of windows but after refresh the reference to them is lost.
Is there any other way to catch this event?
This is my code related to closing windows (running closeAll()
outside unload
and onbeforeunload
closes all my opened window, but not when the page is refreshed):
window.unload = function() {
closeAll();
}
window.onbeforeunload = function() {
closeAll();
}
var closePopup = function(popup) {
removePopup(popup);
popup.close();
};
var closeAll = function() {
for (var popup in _this.popups) {
closePopup(_this.popups[popup]);
}
}
This works only in Chrome but not in Firefox and IE (latest versions).
Child Windows. A child window has the WS_CHILD style and is confined to the client area of its parent window. An application typically uses child windows to divide the client area of a parent window into functional areas.
You could do something like this. var intervalID, childWindow; childWindow = window. open("http://www.google.com"); function checkWindow() { if (childWindow && childWindow. closed) { window.
If you open all child windows with window. open, include this javascript in all pages, then CloseAll(false); from any included page will close all child, grandchildren, great-grand... etc., and redirect the first (root) page to login.
In the HTML markup of the Child page we need to place the JavaScript function RefreshParent which is called attached to the browser onbeforeunload event. Thus when the Child page popup window is closed the parent page is refreshed.
use this
var popup = window.open("popup.html", "popup", "width=200,height=200");
window.onunload = function() {
if (popup && !popup.closed) {
popup.close();
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With