A hyperlink can reference any file, not just a Web document . You can take advantage of this to link to other content such as Microsoft Office documents, compressed archive files such as .zip files, and even executable program files such as setup utilities for programs that you want to provide to your visitors . The procedure for linking to other content is the same as for linking to a Web page; the only difference is the file name you enter in the hyperlink .
Note You can create hyperlinks to pictures, but linking to a picture by using the <a> tag opens the picture in its own window rather than displaying it on the Web page. You will learn in Chapter 9 how to place pictures on the pages themselves.
Before you create a link to non-HTML content, you need to remember that not everyone has the same software . At first, it might seem like a great idea to provide a set of reports as Word documents, for example, but what about people who don’t have Word installed?
Some browsers have a feature that automatically tries to download an appropriate viewer, player, or plug-in (an extension to the browser for handling a certain type of file) for anything it can’t display as native content . That’s a great feature when it works, but it’s not reliable because not all your Web visitors will have a browser with this capability . If you don’t provide an HTML alternative for a proprietary-format file, you should at least provide a hyperlink to a free viewer that can display that file type . This is especially important with audio and video clips, which you will learn about in Chapter 15, “Incorpo-rating Sound and Video .”
Here are some of the popular viewers and the addresses where they can be downloaded:
● Adobe Reader:
get.adobe.com/reader
● Microsoft Download Center, offering Microsoft Office viewers (PowerPoint, Excel, Word) and trial versions of Microsoft Office
http://www.microsoft.com/downloads/en/default.aspx
Tip After the 60-day trial period, the Office trial version software operates in reduced functionality mode that still allows users to view documents created with Word, Excel, and PowerPoint.
In this exercise, you will create a hyperlink to a Microsoft Word file, and to the Microsoft Download Center page .
Hyperlinking to Other Content 79
SET UP Use the index.htm, spray.htm, and spray.doc files in the practice file folder for this topic. These files are located in the Documents\Microsoft Press\HTML5 SBS\05Links\LinkingOther folder. Open the index file in Notepad and in Internet Explorer.
1.
In the index file, locate the list item Microsoft Word version and enclose it with an<a> tag that points to the spray document .
<li><a href="spray.doc">Microsoft Word version</a></li>
2.
After the hyperlink to the Word document, add a hyperlink that references the downloadable Microsoft Word viewer .<li><a href="spray.doc">Microsoft Word version</a> - <a href="
http://www.microsoft.com/downloads/en/default.aspx ">(Download free Word viewer)</a></li>
3.
Save the file, and then refresh the Internet Explorer display .4.
In Internet Explorer, click Download free Word viewer and confirm that the Microsoft Download Center page appears . If it does not, you have probably made a typographical error in the hyperlink; make corrections if needed .5.
Click the Back button to return to the referring page, and then click Microsoft Word version .6.
If a dialog box appears prompting you to save or open the file, click Open in Word 97 - 2003, or whatever variant of Open the dialog box shows .Depending on the Windows version and browser, the dialog box wording might vary . Here’s how it looks in Windows 7 with Internet Explorer 9:
The spray document opens in Word .
CLEAN UP Close the Notepad and Internet Explorer windows and exit Word.
Key Points 81
Key Points
● To create a hyperlink, use the <a> tag with the href= attribute . The <a> tag is two-sided, so add </a> after the text that you use as the hyperlink .
● Use absolute paths (that is, paths containing the full location of the file) when refer-ring to content outside your own Web site . Use relative paths when referrefer-ring to files in the same folder as the current page, or in a parent or child folder .
● To open a hyperlink target in a new window, include the target=”_blank” attribute in the <a> tag .
● To create a hyperlink that opens a pre-addressed e-mail message, precede the address with mailto:, for example, mailto:[email protected] .
● To create an anchor point, use the name= attribute with the <a> tag, for example,
<a name=”equipment”> .
● To reference an anchor point, reference the anchor point name, but remember to precede the name with a pound symbol (#) in the href= attribute, as in
<a href=”#equipment”> .
● You can create hyperlinks to other types of content besides Web pages, but you should include hyperlinks to viewers for any content types that might not be supported by all browsers, and/or make HTML or plain-text alternative versions available .
● To provide a viewer for a type of content, create a hyperlink that points to a site from which it can be downloaded, or store the viewer on your own Web site and provide a link to it .
83