Many Web sites contain a page with links to related content found on other Web sites. When creating links to other sites, you have many options regarding the window in which the new site will load. In all cases, however, the href attribute must be set to a complete URL (for example, http://www.google.com).
If you wish the new site to replace the page you are viewing, use target="_top" as an attribute in the <a> tag.
If you wish the new site to load in a new window, use target="_blank".
Type the code below into any text editor and save it with the name "lesson07.html" in your "mySite" folder. You may view the completed lesson in a new window by clicking here . After you create this page, open it in your Web browser.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XHTML Lesson 7: Links to other sites</title>
</head>
<body bgcolor="white">
<h1>Links to Other Sites</h1>
<p>Many Web sites contain a page with links to related content found on
other
Web sites. When creating links to other sites, you have many options regarding
the window in which the new site will load.</p>
<p>Here are some example links to other sites.</p>
<p><a href="http://www.stevenestrella.com/composers" target="_top">Dr.
Estrella's Incredibly Abridged Dictionary of Composers</a><br />
(Replaces this window)<br />
If you click this link, the page you are reading will be replaced by the
Dictionary of Composers. When you see the new page, click the Back button to
return to this page.</p>
<p><a href="http://www.shearspire.com" target="_blank">Shearspire,
Inc.</a><br />
(Creates a new window)<br />
If you click this link, a new window will appear containing the Web site for
Shearspire, Inc. You may drag the new window anywhere on the screen and close
it when you are finished. This page will remain on your screen.</p>
</body>
</html>
The major Web browsers allow you to have multiple windows open simultaneously. As a result, you are free to create links that open in a new window or any existing window. Several window names are reserved. For example, _top refers to the Web browser window that is currently active. When you click on one of multiple windows, the window you click appears on TOP of all the other windows. The reserved name _blank tells the Web browser to create a new window.
<a href="http://www.stevenestrella.com" target="_blank">Opens this link in a new window</a>
<a href="http://www.stevenestrella.com" target="_top">Opens this link in the current window</a>
If you omit the target attribute, the new page will load in the currently active window.
You may use the target attribute with links to external sites and with links to pages within your site.