HTML Objects


<object>

Contents:

1.0 Overview

2.0 Attributes

2.1 CLASSID
2.2 CODEBASE
2.3 CODE
2.4 CODETYPE
2.5 DATA
2.6 TYPE
2.7 ARCHIVE
2.8 DECLARE
2.9 STANDBY

3.0 Design Tradeoffs

4.0 Examples

4.1 Example 1.0
4.2 Example 1.1
4.3 Example 1.2

 

1.0 Overview:

The <object> tag is a new addition to HTML version 4. The purpose of this tag is to provide a modular or flexible tag that can handle various multimedia elements (see Figure 1). Applets, images, video, and embedded HTML documents can all be displayed via the <object> tag. Its modular design provides the web designer with many attributes and the possibility to handle different types of objects in the future. However, there are some inconsistencies in the attributes and the way they are displayed in Internet Explorer and other non-Internet Explorer browsers, such as Netscape and Opera. While the non-Internet Explorer browsers adhere to the W3C standards, Internet Explorer seems to have some extra attributes, which are not specified by the W3C, and causes certain objects to be displayed improperly.

Figure 1

2.0 Attributes:

2.1 CLASSID [optional]

2.2 CODEBASE [optional]

2.3 CODE [required for Internet Explorer browsers]

2.4 CODETYPE [required when CLASSID/CODE is specified]

2.5 DATA [required for certain <object> types]

2.6 TYPE [optional]

2.7 ARCHIVE [optional]

2.8 DECLARE [optional]

2.9 STANDBY [optional]

3.0 Design Tradeoffs:

The <object> tag can be used to replace the <applet> (Example 1.0 and Example 1.1), <img> (Example 1.2), and <iframe> tags, but it is a decision that the web designer should make. Only the <applet> tag should not be used since it is deprecated.

The nice thing about the <object> tag is its ability to be nested. This feature is useful when a browser cannot display the intended object. In this case, the browser will try to render the object at each nested level. It's like a nested if,else programming statement. If all the nested objects cannot be rendered, it is good practice to add alternate text to be displayed to the user. The examples in this topic note include alternate text.

You will not loose many of the features available in the <img> and <iframe> tags by switching over to <object> tags. In fact, it is to your advantage to switch over because of the versatility that the <object> tag has to offer. Also, the <img> and <iframe> tags may soon be deprecated by the W3C just as the <applet> tag was. One word of caution: there seems to be a lot of incompatibility and inconsistency with the <object> tag when using different browsers. Netscape and Opera seem to adhere to the W3C specifications, but Internet Explorer seems to be in their own world. I discovered that Opera 6 displays every object on this page and therefore makes it the most compatible HTML browser.

One great advantage of the <object> tag is the ability to declare (via the DECLARE attribute) your objects at the beginning of the HTML page and assign it an ID. You then have the ability to use this ID like a function call later in your HTML document.

4.0 Examples:

Hello World

[Internet Explorer version]
Screen Shot
Hello World Applet
Applet cannot be loaded. Not using IE compatible browser.

Example 1.0

Here's the <object> portion of the HTML code that generated Example 1.0:

<object codetype="application/Java"
        codebase="http://www2.hawaii.edu/~justinhi/applet/"
        code="Hello.class"
        width="150" height="100"
        standby="Please wait...">
	    <! -- Display the following text if object cannot be rendered -->
        Applet cannot be loaded. Not using IE compatible browser.
</object>

This example does the same thing the <applet> tag does except using the <object> tag. Notice how the second to the last line of the code displays the alternate text "Applet cannot be loaded. Not using Internet Explorer compatible browser." This is one of the advantages of using <object> tags. This example will display a message to the right of the screen shot if using a non-Internet Explorer browser. Otherwise the applet should look similar to the one in the screen shot.


Hello World

[Netscape/Opera version]
Screen Shot
Hello World Applet
Applet is not working. Please use a Netscape compatible browser.

Example 1.1

Here's the <object> portion of HTML code that generated Example 1.1:

<object codetype="application/Java"
codebase="../../applet"
classid="Java:Hello.class"
width="150" height="100"
standby="Please wait...">
<! -- If this doesn't work then just print a message.
The codebase attribute could also be a valid URL --> Applet is not
working. Please use a Netscape compatible browser. </object>

This example is similar to Example 1.0 except that it is designed for non-Internet Explorer browsers. The difference is the CLASSID and CODE attributes. The CLASSID (a W3C standard) attribute is used for non-Internet Explorer browsers and the CODE (not a W3C standard) attribute is used by Internet Explorer browsers. The other difference is the way the CODEBASE attribute is specified. This example uses a relative path from the current HTML page to point to the directory that contains the JAVA class file. Example 1.0 uses an absolute path instead. The screen shot displays what the Hello World applet should look like in an Opera browser.


Star Image

[Internet Explorer version]

Screen Shot
Image

Image cannot be found

[Netscape/Opera version]
Screen Shot
Image

Image cannot be found

Example 1.2

Here's the <object> HTML code that generated Example 1.2.

<object data="http://www2.hawaii.edu/~justinhi/images/one_star.gif" 
        height=50 width=75 
        type="image/gif">
        <! -- Display this message if pic not found
This works for Internet Explorer, Netscape, and Opera 6.0 --> Image cannot be found </object> <object data="http://www2.hawaii.edu/~justinhi/images/one_star.gif" type="image/gif">
<! -- Display this message if pic not found
This works for Netscape and Opera -->
Image cannot be found </object>

Example 1.2 should display an image of a single blue star. If you cannot see either image, you are using a browser other than Netscape, Opera, or Internet Explorer. The top image should be seen by any browser, but the bottom image will not work in Internet Explorer browsers because the height and width attributes are not specified. If you are using an Internet Explorer browser, you should not be able to see the Netscape/Opera image of the star. However, if you are using a Netscape or Opera browser, you should be able to see both star images.

 

[View Feedback on this topic] [View Original Object Topic Note]



ICS 415 | Topic Notes | Assignments | Feedback | Links

Last Updated: February 15, 2002