Control window focus
Takeaway: Use the focus() method to control your window focus. Here's how.
By Brent Lee Metcalfe
A window that can't focus is like a plane that can't fly: it contains some pretty interesting stuff, but it can't ascend to the heights that it was built for. I've discussed focusing idiosyncrasies, so let's demo a focusing technique that's compatible across browsers.
When the onClick event handler fires the window titled "focus two!" (spawn) focuses its parent window "focus one!" (the opener) by first detecting whether it's blurred:
function onTop() {
If so, the parent window is brought to the top using the focus() method. Similarly, the parent window detects whether its child (the spawn) is blurred. If so, "focus two!" is placed on top:
function onTop() {
I haven't mentioned any "If nots" in the above because closing one window will close them both.
Brent Lee Metcalfe is a Web architecture consultant.
if (opener.blur) opener.focus();
}
if (spawn.blur) spawn.focus();
}
Print/View all Posts Comments on this article
SponsoredWhite Papers, Webcasts, and Downloads
- Does fragmentation affect SANs, NAS, and RAID? Diskeeper
- Live Webcast: Optimized Virtualization ZDNet
- Live Webcast: Web Threats Don't Discriminate - Large and Small IT Departments Need to be Equally Prepared IronPort Systems
- Yankee Group: Exploring the Benefits of 3G Wireless Integrated into Business-Class Routers Sprint
- How File Fragmentation Occurs on Windows XP / Windows Server 2003 Diskeeper
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET





