Tricks with Windows and Frames

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 because 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. Other times, you might want to open more than one document in multiple windows in a frameset. More commonly, the new document starts the user down a new web of documents, and you want her to see and remember where she came from.

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

Targeting Windows

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

Reference a new name

If you use a name you haven’t previously defined as the value for the target attribute of a hyperlink, the popular browsers 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 because you can subsequently use the name to load other documents into the same window. Using ...

Get HTML & XHTML: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.