Importance of named windows and how to close all child windows | MyThinkPond

One of the questions posed by a friend of mine is this.

In a typical website-application, you spawn a few child windows here and there and because of the nature of the application, you do not have a handle to all the child windows you spawn open... Then how do you close all the child windows that belong to your application when the user logs out of your application or closes the main window with the intent that he/she wants to log out?

Well, Javascript “Named” widows to your rescue.

Let’s say you have a parent page/application that has a bunch of links:

[sourcecode language=“jscript”]

<a href="Javascript: openChildWindow(1);">Open child window 1</a>.

<a href="./WindowOne.html" target="MYAPP_2">Open child window 2</a>.

<a href="Javascript: openChildWindow(3);">Open child window 3</a>.

<a href="Javascript: openChildWindow(4);">Open child window 4</a>.

<a href="./WindowOne.html" target="MYAPP_5">Open child window 5</a>.

<a href="Javascript: openChildWindow(6);">Open child window 6</a>.

<a href="./WindowOne.html" target="MYAPP_7">Open child window 7</a>.

Now goto <a href="./secondPage.html">second page</a> which looses all knowledge of these windows...


Now in the secondPage.html

[sourcecode language=“jscript”] Close All Child Windows.


Essentially the code looks for all windows with a following convention. In this case, all window-names that start with “MYAPP_*” where *=[0 to 10]. You can do the same trick to see if a window is already opened up under a name so that you can open up a window under a new name but based on your convention.

You can download the sample here.


Venkatt Guhesan avatar
About Venkatt Guhesan
Enterprise Software Architect currently working at DataDirect Networks developing a highly scalable monitoring solution called DDN Insight. My passions include all things Open Source including Linux (CentOS, Red Hat, Gentoo, Open Stack, Docker & Ubuntu), embedded ARM processors and microcontrollers (Arduino, UDOO, Cubieboard, BeagleBoard, OnionIO, TI's Zigbee). Coming from an Electrical and Computer Engineering background, working in developing and designing enterprise - distributed, highly scalable software requires a unique set of software skills with a good understanding of the hardware. This makes his work challenging and interesting. In his free time, he spends his time with his family and two children. He also enjoys researching on topics including - world ancient history and yoga. Visit the 'About' section for more details.
comments powered by Disqus