Linking in XHTML 2.0
By Micah Dubinko2005-05-04
The Embedding Attribute Collection
So far, all the links that I've discussed are href-style links, which the user clicks to make things happen. But you'll also encounter links that load immediately -- especially images. For these, XHTML 2.0 defines the Embedding attribute collection.
The showcase attribute in this collection is src, which bears the URL of the remote resource, and normally gets traversed while the main document is loading; it requires no special action from the user. The other attribute, type, provides additional metadata about what?s expected at the other end.
One key design feature that?s easy to miss: If it can be loaded, the linked-to content replaces the element in question; in other words, a fallback mechanism is built-in, even over multiple levels of nesting. Listing 3 shows how this works.
Listing 3. Embedding fallback
<p href="http://scp.example.info" src="cow.jpg" usemap="#map1">In Listing 3, a text-only browser, or a graphical browser with images turned off sees a navigation list, but everyone else sees the interactive image map defined on the p element, the details of which are specified in map1. This fallback behavior is used to good effect with the object element, as shown in Listing 4.
<nl>
<li href="scp.html"/>
<li href="/"/>
</nl>
</p>
Listing 4. Object fallback
<!-- First, try Flash -->Browsers encountering the code in Listing 4 first try to load the Flash applet. If that fails for any reason, the browser attempts to load the JPG image. If that too fails, then the browser displays the innermost alternate text. Web users welcome this kind of flexibility.
<object src="earthtime.swf" type="application/x-shockwave-flash">
<!-- Else, try the image -->
<object src="earthtime.jpg" type="image/jpeg"/">
<!-- Else, alternate text -->
A map of the earth showing night and day
</object>
</object>
Tutorial Pages:
» How XHTML 2.0 is Changing the Way People Think About Web Linking
» Linking: From Any Element
» The Hypertext Attribute Collection
» The Embedding Attribute Collection
» Are We There Yet?
» Resources
First published by IBM DeveloperWorks
