spacer
Yehuda Shiran May 14, 2000
Clicking Away 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

You have probably noticed applications presenting an About box that closes when the user clicks the mouse anywhere in the box. We'll use JavaScript to apply the same effect to a window. First, here's the code that opens the new window:

<SCRIPT LANGUAGE="JavaScript">
<!--

function launchAbout() {
  about = window.open("about.html", "about", "height=75,width=250");
  return false;
}

// -->
</SCRIPT>
<A HREF="about.html" onClick="return launchAbout()">About</A>

You can close the new window by clicking anywhere inside it. We use the following script in the HEAD portion of the about.html document:

<SCRIPT LANGUAGE="JavaScript">
<!--

function closeWin() {
  window.close();
}

if (window.Event) document.captureEvents(Event.ONCLICK);
document.onclick = closeWin;

// -->
</SCRIPT>

For more information about events, refer to Column 9, The Navigator Event Model, Column 10, The Internet Explorer Event Model, and Column 11, The Cross-Browser Event Model. For a similar keyboard implementation, see Hot Keys (November 24, 1999). For a live demo, go to 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