Linking Between Frames


Think back to Lesson 4, "Linking Text and Documents," when you learned how to create hyperlinks. You'll remember that you can use the <a name="x" > tag to name an anchor, or target, within a document that could be linked to directly, as shown in the following code.

<a name="PointA" >Point A</a>


You'll remember that you need to use the anchor tag, <a href="url#anchor">, to surround the text that you want to highlight, as shown in the following example:

<a href="DOC2.htm#PointA">Click Here to go to Point A</a>


All frames also have the name and id attributes assigned to them. You can use that name to specify which frame you want your hyperlink to open in. Let's look at the HTML code for the toc.htm file used in the preceding examples.

<!DOCTYPE html      PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"        xml:lang="en" lang="en"> <head> <title>Table of Contents</title> <style type="text/css"> </style> </head> <body> <p><a href="homepage.htm" target="main">HOME</a></p> <p><a href="page1.htm" target="main">Page 1</a></p> <p><a href="page2.htm" target="main">Page 2</a></p> <p><a href="page3.htm" target="main">Page 3</a></p> <p><a href="page4.htm" target="main">Page 4</a></p> </body> </html>


Now you see a new attribute has been attached to the <a href> tag: target. The target attribute refers to the target frame for the hyperlink. Besides the frame names that you've specified in your frameset document, you can target the following other three names:

  • <a href="url" target="blank"> This tag opens the hyperlink in a new browser window.

  • <a href="url" target="self"> This tag opens the hyperlink in the same window where the hyperlink was. If the hyperlink was in a frame, the link will open in the same frame, replacing that frame document.

  • <a href="url" target="top"> This tag opens the hyperlink in the same browser window. If the hyperlink was in a frame, the link will open in the same frame, replacing the entire frameset.

Target Frame

The name of the frame in which a hyperlink will open.


Caution

Always specify the target attribute whenever you are working with frames. If you don't specify the target frame, the browser generally will replace the current frame with the target document, which might not be what you'd intended.




Sams Teach Yourself HTML in 10 Minutes
Sams Teach Yourself HTML in 10 Minutes (4th Edition)
ISBN: 067232878X
EAN: 2147483647
Year: 2004
Pages: 151
Authors: Deidre Hayes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net