Read HTML The Definitive Guide Online
Authors: Chuck Musciano Bill Kennedy
13.2 Embedded Content
In this section, we cover three tags that support embedded content. The
4.0 standard. It is a generalized hybrid of the deprecated
The HTML 4.0 standard strongly encourages you to use the
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
The
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
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
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
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