home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

HTML: The Definitive Guide

Previous Chapter 15
Tips, Tricks, and Hacks

15.6 Creating New Windows

For the vast majority of links in your documents, you'll want the newly loaded document displayed in the same window, replacing the previous one. That makes sense, since your users usually follow a sequential path through your collection.

But sometimes it makes sense to open a document in a new window, so that the new document and the old document are both directly accessible on the user's screen. If the new document is related to the original, for instance, it makes sense to have both in view. More commonly, the new document starts the user down a new web of documents, and you want them to see and remember where they came from.

Regardless of the reason, it is easy to open a new browser window from your HTML document. All you need to do is add the target attribute in the appropriate hyperlink (<a>) tag.

We normally use the target attribute to load a document into a specific frame that you've named in a frameset. It also serves to create a new window by one of two methods:

  • Reference a new name. If you haven't previously defined a name and then use that new name as the value for the target attribute of a hyperlink, Netscape and Internet Explorer automatically create a new window with that name and load the referenced document into that window. This is the preferred way to create new windows, since you can subsequently use the name to load other documents into the same window. Using this technique, you can control which document gets loaded where.

  • Create an unnamed window. Some browsers like Netscape and Internet Explorer support a special target named _blank[2] that lets you create a new window. The _blank window has limited use, though, because it is nameless--you cannot direct any other documents into that window. (New documents loaded via hyperlinks selected by the user within the window get displayed in that same window, of course.)

    [2] Some browsers also accept the name _new. If you can't get _blank to work with your browser, try _new.

Previous Home Next
Transparent Images Book Index Multiple Frames in One Link

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell