spacer
Yehuda Shiran May 15, 2000
Closing Child Windows
Tips: May 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The dependent window feature specifies whether the window should be a dependent child of the current (opener) window. A dependent window closes when its parent window closes. This dependent feature is only supported by Navigator 4 and above. However, we can use a bit of JavaScript to deliver a cross-browser solution. Let's use the following function to open our dependent window:

function openDep() {
  win = window.open("depwin.html", "dep", "height=200,width=400");
}

We'll include an onUnload event handler to close the dependent window when the current window closes or a new URL is loaded:

<BODY onUnload="closeDep()">

Note that the new window will close when the current document unloads, even if the current window is still open. Here's the code for the closeDep() function:

function closeDep() {
  if (win && win.open && !win.closed) win.close();
}

Notice that we must check if the window exists before we attempt to close it. To learn more, have a look at a complete demonstration in Tutorial 1.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint