HTML Hot Tip: Opening A New Window With A Link

For the vast majority of links in your documents, you'll want the referenced document to be displayed in the window where the current document is being displayed. This makes sense, since your users are following a path through your documents, always looking at the most recent one.

Sometimes it makes sense to open a document in a new window, so that the new document and the old document are both visible on the user's screen. Perhaps the new document is related to the original so that it makes sense to view both simultaneously. More commonly, the new document may take the user down a new web of documents and you want them to be able to see where they came from.

Regardless of the reason, it is easy to open a new browser window when a link is selected. All you need to do is add the target attribute to the appropriate <a> tag.

Normally, the target attribute is used to load a document into a specific frame that you've previously named. It can also be used to create new windows using one of two methods:

Making this work is easy. For example, this link

     <a href="http://members.aol.com/htmlguru" target="guru_window">Try it!</a>
opens my HTML Guru home page in a new window named "guru_window". Try it!

If you reuse that name, the document will replace the current document in that page. You can load my Hot Tips index into that same window by using the same target name with the appropriate URL. Try it!

There are a few other special target names that I'll cover in a future hot tip. Check back soon!