Closing all child windows












-1















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.










share|improve this question


















  • 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
















-1















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.










share|improve this question


















  • 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














-1












-1








-1








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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














  • 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








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












1 Answer
1






active

oldest

votes


















0














I went with the idea that felix and justin presented.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    I went with the idea that felix and justin presented.






    share|improve this answer




























      0














      I went with the idea that felix and justin presented.






      share|improve this answer


























        0












        0








        0







        I went with the idea that felix and justin presented.






        share|improve this answer













        I went with the idea that felix and justin presented.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 7 at 18:32









        pithhelmetpithhelmet

        99252150




        99252150
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            WPF add header to Image with URL pettitions [duplicate]