Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Linking to specific windows

If you don't tell the browser where you want to open the link, it displays the destination page in the current. This is OK if you just want to put new content into the same window. You can, however, choose to open a page in a specific window or a new window. This means that the page with the link stays open and new window appears with the destination page in it. You can then toggle between the information in both windows.

You need to add a target if you want the link to open in another window or frame than the link itself is placed in. To do this, you use the target attribute of the <a> tag. For example

You can visit <a href="http://www.ann.com/" target="_blank">
Ann’s Web site</a> for more information

This link will open the home page in a new window.

You have several different targets:

  • name. Loads the page into a window with a specific name
  • _blank. Loads the page in a new browser window
  • _self. Loads the page into the current window. I can’t see that you would use this often because it is the same as not specifying a target at all
  • _parent. Loads the page into the parent of the window that contains the link. This is one way to replace a collection of frames with a single document, provided that the link to the document originates from one of the frames. You'll need to pay attention to how you create and nest your framesets so that references to target="_parent" function correctly
  • _top. The _top target works like _parent except that it loads the page into a top-level browser window; all intermediate framesets will be overwritten. Use this option for links that reference external sites outside of your frame structure; it allows those pages to load over top of your frames so they look like the original author intended them to

If you have lots of links in your frames that point to the same target, it can be tedious to make sure that every link has the correct target attribute. To make life easier, use the <base> tag in your document head to define the default target for all links in your document.

Usually, you use the <base> tag to set the base URL against which all relative URLs in your document will be resolved. If you the target attribute to the <base> tag, you also can set the default target.