spacer
Yehuda Shiran May 14, 2000
Clicking Away Windows
Tips: May 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business