codetype
This specifies the Internet Media Type expected by the browser
when downloading an object of the type that has been referenced in the classid attribute.
It is only relevant if a classid attribute has already been specified. The syntax
is as follows:
codetype="media_type"
Browsers may use the value of the codetype attribute to skip over unsupported media
types, without the need to download unnecessary objects. See "type" for
more details on media types.
declare
This declares the object without instantiating it. The syntax is simply
declare.
Use this when you are creating cross-references to objects that occur later in the
document, or when you are using the object as a parameter within another object.
data
This defines the URL, or the data itself, that is the source for the
object. The syntax is:
data="source"
where source can be a URL from which the data can be downloaded, or the data itself
as a string of hexadecimal values. We'll look at an example of this later in the
chapter.
height and width
These specify the height and width that an object is to be displayed
at. The syntax is:
width="n"
height="n"
where n is the width or height in pixels. This can also be expressed as a percentage
value, in which case, the value should be appended with a % symbol.
When using the <object> element to display images width and height are scaleable.
That is, we can use them to specify the size of box that we want the image to fit
into, and the browser will scale the image to suit, which is exactly the same as
how the <img> element handles images. However, there is an exception to this
rule, in that IE 5.5 puts the image in its original size into a frame, and this
frame is scaled to the dimensions specified by the width/height. We'll see more
on this in a minute.
Using width and height with the <object> element helps the page to load faster,
because the browser can lay out the rest of the page, as it knows the dimensions
of the object before loading it.
hspace and vspace
These attributes are used to control the white space around an object.
The syntax is:
hspace="n"
vspace="n"
where n is a numerical value in pixels. Other elements next to, above, and below
the image will be moved away by the specified number of pixels. These attributes
are now deprecated with the HTML 4.01 standard.
name
This attribute provides a name to refer to the object by. The syntax
is:
name="name"
where name is a unique name within the page. In HTML 4.01, this is equivalent to
the id attribute, but is only required for form submission.
standby
This attribute specifies a text string that will be used while the object
data is loading. The syntax is:
standby="text"
where text is a word, phrase or sentence that describes the object, or provides
a meaningful description of the object, when displayed while it loads.
tabindex
This is the tab index for the object within the page. The syntax is:
tabindex="n"
where n is the position within the tabbing order of the page. By default, all elements
in the page that can receive the input focus are part of the tabbing order, in the
order they are defined in the HTML source. Each receives the focus in turn as the
Tab key is pressed. By setting the value of tabindex to -1, the element is removed
from the tabbing order. See Chapter 6, for more on tabindex and focus.
usemap
This attribute indicates that the object is an image map containing
defined areas that are individual hyperlinks. The usemap attribute is used to specify
the map file to use with this object. The standard allows for a complete URL to
an external map file, but usually a reference #mapName to an inline mapElement is
used. Also, note that this attribute only exists in Internet Explorer 6, and not
earlier IE versions. There is more information on image maps in Chapter 5.
Internet Explorer <object>
Extensions
Internet Explorer adds other attributes to the <object> element:
|
align |
accesskey |
alt |
code |
|
datafld |
hidefocus |
notab |
type |
|
unselectable |
Note: only the align attribute is actually supported in IE 5.5 onwards, the
rest are IE 4 only. Now let's look at these in turn:
align
The syntax for the align attribute in this context is slightly different
from normal:
accesskey
This attribute defines the "hot-key" that can be used to activate
the element, or switch the input focus to it. This is used where a hyperlink takes
the form of an image, rather than a text string. For details of using an image as
a hyperlink see Chapter 4. For more about the uses of the accesskey attribute, see
Chapter 6.
alt
This defines a text alternative to the graphic. See Chapter 5 for more
details.
code
This attribute defines the URL to the Java class file implementing the
object, if this is the object source instead of an image. Its syntax is:
code="url"
datafld and datasrc
These attributes are used to connect the <object> element to a
client-side cached data source in Internet Explorer 4, in a technique called data
binding. These have since been removed in Internet Explorer 6. For a look at using
these attributes, see the "<frame>" section of Chapter 8.
hidefocus
This attribute holds a value indicating whether or not the object is
indicated visibly when the element is in focus. See Chapter 8 for more information.
notab
This attribute was present very briefly in Internet Explorer 3, but
was dropped by the time of version 4. It was used to exclude an element from the
tabbing order, but now this can be achieved by setting the tabindex attribute to
–1.
type
This attribute defines the MIME type for the object, as defined in the
registry on a Windows Machine. The syntax is:
type="mime-type"
where mime-type is a unique text string of a standard format, which tells the browser
what kind of information the file contains, and which application to use to read
or execute it – as appropriate. The MIME-types for popular image formats are
"image/gif", "image/jpeg", and "image/png". This is
overridden by the classid attribute.
unselectable
This attribute specifies that the element cannot be selected. The syntax
is:
unselectable="on | off"
If it is set to off (the default), then the element can be selected. Setting it
to on makes the object unselectable.
Tags <object> Can Enclose
The <object> element operates in conjunction with the <param>
element, which is used to specify the different parameters that each object can
take. These parameters are values that the object will require at run time. They
must be placed at the beginning of the content of the <object> element.
The <param> Element
The param element can take the following attributes:
name type value valuetype
plus the universal attributes and core events discussed in Chapter 2. The majority
of these additional elements, which are specific to a particular object, will just
use a name and a value.
name
This attribute specifies the name or property of the parameter. This
attribute is mandatory for every <param> element. The syntax is:
name="string"
value
his attribute specifies the value to set for the parameter. The syntax
is:
value="string"
type
This attribute has the value of the MIME type that is retrieved if valuetype
(the data type of the value attribute) is set to ref. The syntax is:
type="string"
valuetype
This attribute specifies how the parameter value will be obtained. The
syntax is:
valuetype="data | ref | object"
ref is via a URL, while data is the default, an implicit value, and object is an
identifier that refers to the id of another object defined in the page. IE 6 is
the first IE version to support valuetype for the <param> element.
Using the <object> Element
The <object> element is a general-purpose element, designed to
insert many different types of content into an HTML document. In order to cope with
this diversity, the type attribute is used to indicate the type of data the object
displays, and the codetype attribute indicates the type of application that implements
the display of the data. Of interest to us when working with images, is the type
attribute, which is a string description of the content – such as "image/gif"
for a GIF image, or perhaps "video/avi" for an AVI video clip. In general
terms for types other than video, audio, or text, the application that is required
to display the data is defined by "application/<document_type>".
In the case of the generic image types, like GIF and JPEG, the browser itself handles
the display of the image.
In Windows, a list of all the MIME types supported by your machine can be found
in registry under: HKEY_CLASSES_ROOT\MIME\Database\ContentType\, which can be used
by all browsers.
Specifying the Data
The data attribute provides the data for the object, either as a URL
from where it can be downloaded, or inline as a string of values. As an example,
this code will display an AVI file named MyVideo.avi. If the browser doesn't support
the <object> element, it will display the text My Video:
This is a general example of how we can take advantage of the <object> element
as a
containing element.
The type attribute, however, is optional; but if it isn't present, then the only
way that the browser can be sure of knowing whether it can handle the object is
by downloading it first – not all files can be uniquely identified from, say,
a file extension. In addition, not all files necessarily have to have the correct
extension anyway, and not all systems even use file extensions. By including the
type attribute, we can tell the browser exactly what type of file it is. Then, if
it can't handle it, it won't waste time and bandwidth downloading it.
Fall Back in Browsers That Don't
Support an Object
If the browser recognizes the <object> element, then all well
and good – the object will be invoked. However, if it doesn't recognize the
<object> element, or can't handle the data that forms the source of the object,
we can ensure that an alternative will be displayed.
We can include text and other elements that are only visible on a browser that either
doesn't recognize the <object> element, or that can't handle the content type
of the data it specifies. We do this by placing text or other elements between the
opening and closing <object> tags, and outside any parameter tags. Here's
an example:
In this case, browsers that support the <object> element should display a
video clip. However, if the browser either doesn't support the <object> element,
or can't display AVI files, the viewer will see an ordinary image defined by the
<img> element. And if the browser doesn't recognize the <img> element,
or can't display the content of it for any reason, the alternative text in the <img>
element's alt attribute will be displayed.