Closing all child windows
The web site could spawn one or more pop up windows.
When the main browser window is closed, i would like all the child windows to be closed as well.
Currently, I am performing this
$(window).on('unload', function () {
if (_chatWindow && !_chatWindow.closed)
{
_chatWindow.close();
};
if (_wazeWindow && !_wazeWindow.closed)
{
_wazeWindow.close();
};
if (_mapWindow && !_mapWindow.closed)
{
_mapWindow.close();
};
});
This seems to work if each child window is opened, but if, for example the _chatWindow is not opened, the _wazeWindow and _mapWindow windows are not being closed.
Does anyone have any suggestions on a way to ensure all the child popup windows can be closed when the parent window is closed.
javascript
add a comment |
The web site could spawn one or more pop up windows.
When the main browser window is closed, i would like all the child windows to be closed as well.
Currently, I am performing this
$(window).on('unload', function () {
if (_chatWindow && !_chatWindow.closed)
{
_chatWindow.close();
};
if (_wazeWindow && !_wazeWindow.closed)
{
_wazeWindow.close();
};
if (_mapWindow && !_mapWindow.closed)
{
_mapWindow.close();
};
});
This seems to work if each child window is opened, but if, for example the _chatWindow is not opened, the _wazeWindow and _mapWindow windows are not being closed.
Does anyone have any suggestions on a way to ensure all the child popup windows can be closed when the parent window is closed.
javascript
1
Are you getting an error in the console? Personally I would generalize this, maintain an array of windows instead and then dochildWindows.forEach(w => !w.closed && w.close())
.
– Felix Kling
Jan 3 at 1:06
1
const childWindows = [_chatWindow, _wazeWindow, _mapWindow]; childWindows.forEach(w => w && !w.closed && w.close && w.close())
– justin.m.chase
Jan 3 at 1:16
I've used the array technique as suggested by @FelixKling. It worked in the past and it's working right now. What browser are you using and could you provide a code snippet that reproduces the problem please?
– traktor53
Jan 3 at 1:17
Great ideas!!! i went with justin chase comment. please provide it as an answer,
– pithhelmet
Jan 3 at 1:24
add a comment |
The web site could spawn one or more pop up windows.
When the main browser window is closed, i would like all the child windows to be closed as well.
Currently, I am performing this
$(window).on('unload', function () {
if (_chatWindow && !_chatWindow.closed)
{
_chatWindow.close();
};
if (_wazeWindow && !_wazeWindow.closed)
{
_wazeWindow.close();
};
if (_mapWindow && !_mapWindow.closed)
{
_mapWindow.close();
};
});
This seems to work if each child window is opened, but if, for example the _chatWindow is not opened, the _wazeWindow and _mapWindow windows are not being closed.
Does anyone have any suggestions on a way to ensure all the child popup windows can be closed when the parent window is closed.
javascript
The web site could spawn one or more pop up windows.
When the main browser window is closed, i would like all the child windows to be closed as well.
Currently, I am performing this
$(window).on('unload', function () {
if (_chatWindow && !_chatWindow.closed)
{
_chatWindow.close();
};
if (_wazeWindow && !_wazeWindow.closed)
{
_wazeWindow.close();
};
if (_mapWindow && !_mapWindow.closed)
{
_mapWindow.close();
};
});
This seems to work if each child window is opened, but if, for example the _chatWindow is not opened, the _wazeWindow and _mapWindow windows are not being closed.
Does anyone have any suggestions on a way to ensure all the child popup windows can be closed when the parent window is closed.
javascript
javascript
asked Jan 3 at 1:01
pithhelmetpithhelmet
99252150
99252150
1
Are you getting an error in the console? Personally I would generalize this, maintain an array of windows instead and then dochildWindows.forEach(w => !w.closed && w.close())
.
– Felix Kling
Jan 3 at 1:06
1
const childWindows = [_chatWindow, _wazeWindow, _mapWindow]; childWindows.forEach(w => w && !w.closed && w.close && w.close())
– justin.m.chase
Jan 3 at 1:16
I've used the array technique as suggested by @FelixKling. It worked in the past and it's working right now. What browser are you using and could you provide a code snippet that reproduces the problem please?
– traktor53
Jan 3 at 1:17
Great ideas!!! i went with justin chase comment. please provide it as an answer,
– pithhelmet
Jan 3 at 1:24
add a comment |
1
Are you getting an error in the console? Personally I would generalize this, maintain an array of windows instead and then dochildWindows.forEach(w => !w.closed && w.close())
.
– Felix Kling
Jan 3 at 1:06
1
const childWindows = [_chatWindow, _wazeWindow, _mapWindow]; childWindows.forEach(w => w && !w.closed && w.close && w.close())
– justin.m.chase
Jan 3 at 1:16
I've used the array technique as suggested by @FelixKling. It worked in the past and it's working right now. What browser are you using and could you provide a code snippet that reproduces the problem please?
– traktor53
Jan 3 at 1:17
Great ideas!!! i went with justin chase comment. please provide it as an answer,
– pithhelmet
Jan 3 at 1:24
1
1
Are you getting an error in the console? Personally I would generalize this, maintain an array of windows instead and then do
childWindows.forEach(w => !w.closed && w.close())
.– Felix Kling
Jan 3 at 1:06
Are you getting an error in the console? Personally I would generalize this, maintain an array of windows instead and then do
childWindows.forEach(w => !w.closed && w.close())
.– Felix Kling
Jan 3 at 1:06
1
1
const childWindows = [_chatWindow, _wazeWindow, _mapWindow]; childWindows.forEach(w => w && !w.closed && w.close && w.close())
– justin.m.chase
Jan 3 at 1:16
const childWindows = [_chatWindow, _wazeWindow, _mapWindow]; childWindows.forEach(w => w && !w.closed && w.close && w.close())
– justin.m.chase
Jan 3 at 1:16
I've used the array technique as suggested by @FelixKling. It worked in the past and it's working right now. What browser are you using and could you provide a code snippet that reproduces the problem please?
– traktor53
Jan 3 at 1:17
I've used the array technique as suggested by @FelixKling. It worked in the past and it's working right now. What browser are you using and could you provide a code snippet that reproduces the problem please?
– traktor53
Jan 3 at 1:17
Great ideas!!! i went with justin chase comment. please provide it as an answer,
– pithhelmet
Jan 3 at 1:24
Great ideas!!! i went with justin chase comment. please provide it as an answer,
– pithhelmet
Jan 3 at 1:24
add a comment |
1 Answer
1
active
oldest
votes
I went with the idea that felix and justin presented.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015099%2fclosing-all-child-windows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I went with the idea that felix and justin presented.
add a comment |
I went with the idea that felix and justin presented.
add a comment |
I went with the idea that felix and justin presented.
I went with the idea that felix and justin presented.
answered Jan 7 at 18:32
pithhelmetpithhelmet
99252150
99252150
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015099%2fclosing-all-child-windows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Are you getting an error in the console? Personally I would generalize this, maintain an array of windows instead and then do
childWindows.forEach(w => !w.closed && w.close())
.– Felix Kling
Jan 3 at 1:06
1
const childWindows = [_chatWindow, _wazeWindow, _mapWindow]; childWindows.forEach(w => w && !w.closed && w.close && w.close())
– justin.m.chase
Jan 3 at 1:16
I've used the array technique as suggested by @FelixKling. It worked in the past and it's working right now. What browser are you using and could you provide a code snippet that reproduces the problem please?
– traktor53
Jan 3 at 1:17
Great ideas!!! i went with justin chase comment. please provide it as an answer,
– pithhelmet
Jan 3 at 1:24