HTML The Definitive Guide (129 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

BOOK: HTML The Definitive Guide
6.41Mb size Format: txt, pdf, ePub

Chapter 13

Executable Content

 

13.2 Embedded Content

In this section, we cover three tags that support embedded content. The tag is in the HTML

4.0 standard. It is a generalized hybrid of the deprecated tag for embedding applets, particularly Java, and the tag extension that lets you include an object whose MIME type references the plug-in needed to process and possibly display that object.

The HTML 4.0 standard strongly encourages you to use the tag to include applets as well as the variety of discrete inclusions in your documents, even images (although the standard did not go so far as to deprecate the tag). Use with the classid attribute to insert Java and other applets into a document, along with their execution parameters as contents of the associated tag. And with , use the data attribute to download and display non-HTML content, such as multimedia, in the user's computing environment. Object data may be processed and rendered by an included applet, by utilities that come with your browser, or by a plug-in ("helper") application that the user supplies.

For applets, the browser creates a display region in the containing text flow exactly like an inline image: without line breaks and as a single large entity. The browser then downloads and executes the applet's program code, if specified, and downloads and renders any included data just after download and display of the HTML document. Execution of the applet continues until the code terminates itself or when the user stops viewing the page containing the applet.

With data, the browser decodes the object's data type and will either handle its rendering directly, such as with GIF and JPEG images, or invoke an associated plug-in application for the job.

13.2.1 The Tag

The tag was originally implemented by Microsoft to support their ActiveX applets and only later added Java support. In a similar manner, Netscape initially supported the alternative and tags for inclusion objects and later provided limited support for the tag.

All that jostling for position by the browser giants made us nervous, and we were hesitant in previous editions of this book to even suggest that you use at all. We now heartily endorse it, based on the strength of the HTML 4.0 standard. Although not fully supported yet, expect to be well supported soon by the popular browsers, and expect the alternative and tags to be less supported, if not completely ignored, by future HTML 4.0-compliant browsers.


Function:

Embed an object or applet in a document

Attributes:

ALIGN ONKEYDOWN

ARCHIVE ONKEYPRESS

BORDER ONKEYUP

CLASS ONMOUSEDOWN

CLASSID ONMOUSEMOVE

CODEBASE ONMOUSEOUT

CODETYPE ONMOUSEOVER

DATA ONMOUSEUP

DECLARE SHAPES

DIR STANDBY

HEIGHT STYLE

HSPACE TABINDEX

ID TITLE

LANG TYPE

NAME USEMAP

NOTAB

VSPACE

ONCLICK WIDTH

ONDBLCLICK

End tag:

; never omitted

Contains:

object_content

Used in:

text

The contents of the tag may be any valid HTML content, along with tags that pass parameters to an applet. If the browser can retrieve the requested object and successfully process it, either by executing the applet or by processing the object's data with a plug-in (helper) application, the contents of the tag, except for the tags, are ignored. If any problem occurs during the retrieval and processing of the object, the browser won't insert the object into the document, but instead will display the contents of the tag, except for the tags. In short, you should provide alternative content for browsers that cannot handle the tag or if the object cannot be successfully loaded.

13.2.1.1 The classid attribute

Use the classid attribute to specify the location of the object, typically a Java class, that you want included by the browser. The value may be an absolute or relative URL of the desired object. Relative URLs are considered to be relative to the URL specified by the codebase attribute if it is provided; otherwise they are relative to the current document URL.

For example, to execute a clock Java applet contained in a file named
clock.class
, you might include in your HTML document the code:


The browser will locate the code for the applet using the current document's base URL. Hence, if the current document's URL is:

http://www.kumquat.com/harvest_time.html

the browser will retrieve the applet code for our clock class example as: http://www.kumquat.com/clock.class

13.2.1.2 The codebase attribute

Use the codebase attribute to provide an alternative base URL from which the browser will retrieve an object. The value of this attribute is a URL pointing to a directory containing the object referenced by the classid attribute. The codebase URL overrides, but does not permanently replace, the document's base URL, which is the default if you don't use codebase.
[Referencing Documents: The URL, 7.2]

Continuing with our previous examples, suppose your document comes from
http://www.kumquat.com
, but the clock applet is kept in a separate directory named classes. You cannot retrieve the applet by specifying classid= classes/clock.class. Rather, include the codebase attribute and new base URL:


which resolves to the URL:

http://www.kumquat.com/classes/clock.class Although we used an absolute URL in this example, you also can use a relative URL. For instance, applets typically get stored on the same server as the host HTML documents, so we'd usually be better off, for relocation's sake, specifying a relative URL for the codebase, such as:

The classid attribute is similar to the code attribute of the tag, providing the name of the file containing the object, and is used in conjunction with the codebase attribute to determine the full URL of the object to be retrieved and placed in the document.

13.2.1.3 The archive attribute

For performance reasons, you may choose to preload collections of objects contained in one or more archives. This particularly true of Java-based applications, where one Java class will rely on many other classes to get its work done. The value of the archive attribute is a quote-enclosed list of URLs, each pointing to an archive to be loaded by the browser before rendering or executing the object.

13.2.1.4 The codetype attribute

The HTML 4.0 standard codetype attribute is required only if the browser cannot determine an applet's MIME type from the classid attribute, or if the server does not deliver the correct MIME type when downloading an object. This attribute is nearly identical with type (section 13.2.1.6), except that it is used to identify program code type, whereas type should be used to identify data file types.

The following example explicitly tells the browser that the object's code is Java:

13.2.1.5 The data attribute

Use the data attribute to specify the data file, if any, that is to be processed by the object. The data attribute's value is the URL of the file, either absolute or relative to the document's base URL or to that which you provide with the codebase attribute. The browser determines the data type by the type of object that is being inserted in the document.

This attribute is similar to the src attribute of the tag in that it downloads data to be processed by the included object. The difference, of course, is that the data attribute lets you include just about any file type, not just an image file. In fact, the tag expects, but doesn't require, that you explicitly name an enabling application for the object with the classid attribute, or indicate the MIME type of the file via the type attribute to help the browser decide how to process and render the data.

Other books

Hotel Mirador by Rosalind Brett
A Woman's Heart by Morrison, Gael
Fire Baptized by Kenya Wright
Unashamed by Janson, Emma
Life on the Run by Bill Bradley
When the Marquess Met His Match by Laura Lee Guhrke - An American Heiress in London 01 - When the Marquess Met His Match
Stranger by Sherwood Smith
The Passenger by Lisa Lutz

© 100 Vampire Novels China Edition 2015 - 2024    Contact for me [email protected]