Section F.6. Linking


F.6. Linking

One of the most important XHTML features is the hyperlink, which references (or links to) other resources, such as XHTML documents and images. In XHTML, both text and images can act as hyperlinks. Web browsers typically underline text hyperlinks and color their text blue by default, so that users can distinguish hyperlinks from plain text. In Fig. F.5, we create text hyperlinks to four different Web sites.

Figure F.5. Linking to other Web pages.

  1  <?xml version = "1.0" ?>  2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  3     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  4  5  <!-- Fig. F.5: links.html       -->  6  <!-- Introduction to hyperlinks -->  7  8  <html xmlns = "http://www.w3.org/1999/xhtml">  9     <head> 10        <title>Internet and WWW How to Program - Links </title> 11     </head> 12 13     <body> 14 15        <h1>Here are my favorite sites </h1> 16 17        <p><strong>Click a name to go to that page.</strong></p> 18 19        <!-- Create four text hyperlinks --> 20        <p><a href = "http://www.deitel.com"> Deitel</a></p>          21 22        <p><a href = "http://www.prenhall.com"> Prentice Hall</a></p> 23 24        <p><a href = "http://www.yahoo.com"> Yahoo!</a></p>           25 26        <p><a href = "http://www.usatoday.com"> USA Today </a></p>    27 28     </body> 29  </html> 

Line 17 introduces the strong element. Browsers typically display such text in a bold font. Links are created using the a (anchor) element. Line 20 defines a hyperlink that links the text Deitel to the URL assigned to attribute href, which specifies the location of a linked resource, such as a Web page, a file or an e-mail address. This particular anchor element links to a Web page located at http://www.deitel.com. When a URL does not indicate a specific document on the Web site, the Web server returns a default Web page. This page is often called index.html; however, most Web servers can be configured to use any file as the default Web page for the site. (Open http://www.deitel.com in one browser window and http://www.deitel.com/index.html in a second browser window to confirm that they are identical.) If the Web server cannot locate a requested document, it returns an error indication to the Web browser, and the browser displays a Web page containing an error message to the user.

Anchors can link to e-mail addresses using a mailto: URL. When someone clicks this type of anchored link, most browsers launch the default e-mail program (e.g., Outlook Express) to enable the user to write an e-mail message to the linked address. Figure F.6 demonstrates this type of anchor. Lines 1719 contain an e-mail link. The form of an email anchor is <a href ="mailto:emailaddress">...</a>. In this case, we link to the e-mail address deitel@deitel.com.

Figure F.6. Linking to an e-mail address.

  1  <?xml version = "1.0" ?>  2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  3     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  4  5  <!-- Fig. F.6: contact.html  -->  6  <!-- Adding email hyperlinks -->  7  8  <html xmlns = "http://www.w3.org/1999/xhtml">  9     <head> 10        <title>Internet and WWW How to Program - Contact Page</title> 11     </head> 12 13     <body> 14 15        <p> 16           My e-mail address is 17           <a href = "mailto:deitel@deitel.com"> 18              deitel@deitel.com                  19           </a>                                  20           . Click the address and your browser will 21           open an e-mail message and address it to me. 22        </p> 23     </body> 24  </html> 



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

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