J.5. 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. J.3, we create text hyperlinks to four different Web sites. Line 17 introduces the tag. Browsers typically display text marked up with in a bold font.

Figure J.3. Linking to other Web pages.

(This item is displayed on pages 1331 - 1332 in the print version)

"http://www.w3.org/1999/xhtml"> 9 10


 1  "1.0"?>
 2  "-//W3C//DTD XHTML 1.1//EN"
 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 4
 5 
 6 
 7
 8 
Introduction to hyperlinks 11 12 13 14 15

Here are my favorite sites

16 17

Click a name to go to that page.

18 19 20

21 <a href="</span"> "http://www.deitel.com">Deitel</a> 22

23 24

25 <a href="</span"> "http://www.prenhall.com">Prentice Hall</a> 26

27 28

29 <a href="</span"> "http://www.yahoo.com">Yahoo!</a> 30

31 32

33 <a href="</span"> "http://www.usatoday.com">USA Today</a> 34

35 36 37

Links are created using the a (anchor) element. Line 21 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 often is 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, the server returns an error indication to the Web browser, and the browser displays an error message to the user.


[Page 1333]

Anchors can link to e-mail addresses through 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 J.4 demonstrates this type of anchor.

Figure J.4. Linking to an e-mail address.

(This item is displayed on pages 1333 - 1334 in the print version)

"http://www.w3.org/1999/xhtml"> 9 10


 1  "1.0"?>
 2  "-//W3C//DTD XHTML 1.1//EN"
 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 4
 5 
 6 
 7
 8 
Adding e-mail hyperlinks 11 12 13 14 15

My email address is 16 <a href="</span"> "mailto:deitel@deitel.com"> 17 deitel@deitel.com 18 </a> 19 . Click the address and your browser will 20 open an e-mail message and address it to me. 21

22 23

Lines 1719 contain an e-mail link. The form of an e-mail anchor is <a href="mailto:</tt><span>emailaddress</span><tt>">...</a>. In this case, we link to the e-mail address deitel@deitel.com.


[Page 1333 (continued)]

J 6 Images





C++ How to Program
C++ How to Program (5th Edition)
ISBN: 0131857576
EAN: 2147483647
Year: 2004
Pages: 627
Simiral book on Amazon

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