Thursday, September 06, 2007

Javascript to close all the child windows from a parent window

//The openWindow array will hold the handles of all open child windows
var openWindow = new Array();

//Track open adds the new child window handle to the array.
function trackOpen(winName) {

//loop over all known child windows and try to close them. No error is
//thrown if a child window(s) was already closed.
function closeWindows() {
var openCount = openWindow.length;
for(r=0;r<openCount;r++) {

//Open a new child window and add it to the tracker.
function open1() {
var win1 = open("");

//Open a different child window and add it to the tracker.
function open2() {
var win2 = open("");
//Open whatever the user enters and add it to the tracker
function open3() {
var newURL = document.getElementById("url").value;
var win3=open(newURL);


<input type="button" value="Open 1" onclick="open1()" ID="Button1" NAME="Button1"><br>
<input type="button" value="Open 2" onclick="open2()" ID="Button2" NAME="Button2"><br>
URL: <input type="text" id="url" NAME="url"> <input type="button" value="Open URL" onclick="open3()" ID="Button3" NAME="Button3"><br>
<input type="button" value="Close All" onclick="closeWindows()" ID="Button4" NAME="Button4">


No comments:

Post a Comment

Please post your comments here.....