Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8214935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:37:15+00:00 2026-06-07T11:37:15+00:00

I need to close child windows which has been loaded by a parent window.

  • 0

I need to close child windows which has been loaded by a parent window.
The child windows are opened by using window.open() method.
I need to close this child windows by clicking a logout button or close button which is in parent window.
My code:

    var childWin = [];
    //child window open event
    function child_open(url)
    {
        childWin[childWin.length] = window.open(url);
    }

    //a logout button or close button event
    function parent_close() 
    {
        for (i=0; i<childWin.length; i++) 
        {
            if (childWin[i] == null) return false;
            childWin[i].close();
        }
        window.close();
    }

This code is OK if the parent window don’t postback to server.
When a postback occured in parent window,the value of variable(childWin) disappeared and I can’t close child windows by this code.
Problem is – want to close child windows even the parent postbacked.
Is there a solution for this?
Thanks for all of your interests and replies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:37:18+00:00Added an answer on June 7, 2026 at 11:37 am

    Your array childWin will be cleared each time the page is loaded. So after post back there will be nothing in the array. Thats why the child windows are not getting closed.

    A work around is mentioned here

    Try something like this [not tested, and not sure it will work , just give a try 🙂 ]

    Parent Window (all pages)

    var childStatus = {};
    

    Child Window

    var timerHandler,
        windowName = window.name,
        popupHandle = "";
    
    funciton ChildCallBack()
    {
      try
      {
        if(popupHandle == "" || popupHandle == null)
        {
           popupHandle = window.opener.childStatus[windowName];
           //ChildCallBack(); // no need of ChilCallBack here, since we already have timer
        }
        else
        {
           window.opener.childStatus[windowName] = popupHandle;        
        }
      }
      catch(e)
      {
      }
    }
    
    timerHandler = window.setInterval(ChildCallBack, 500);
    
    function window_onclose()
    {
      try
      { 
        window.clearInterval(timerHandler);
        window.opener.childStatus[windowName] = null;
      }
      catch(e)
      {
      }
    }
    
    window.onclose = window_onclose;
    

    Your Child window open function

    //child window open event
        function child_open(url)
        {
            var winHandle = window.open(url, "GIVE SOME UNIQUE NAME FOR EACH WINDOW HERE");
            winHandle.popupHandle = winHandle;
        }
    

    Your close button event

    //a logout button or close button event
        function parent_close() 
        {
            for (var key in childStatus)
            {
                if (childStatus[key] != null) 
                {
                  childStatus[key].close();
                }
            }
            window.close();
        }
    

    Possible fix for query >> But, after a postback of child ,an error occurs in parent_close() (the value in childStatus[key] is not object and it can not do childStatus[key].close())

    Replace

    timerHandler = window.setInterval(ChildCallBack, 100);
    

    with

    if(popupHandle == "" || popupHandle == null)
    {
       // get the popupHandle from parent window
       popupHandle = window.opener.childStatus[windowName];
       timerHandler = window.setInterval(ChildCallBack, 100);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my web application I need to close the child window whenever the parent
I have a parent window which has a ListView that is bound to an
I have a need to close a parent form from within child form from
I have gtk.Window and I need to catch closure. I need to close the
I used JavaScript to open a new window(child) when user clicks on button from
I have a Windows form application that has a child form that pops up
I need to call an Ajax script to reload data from a child window.
I have a generic subclass of Backbone.View which has a close event listener. var
When the escape key is pressed, I would like to close a child window,
I need to close the colorbox iframe that overlays the website with an onclick

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.