HTML Objects


<object>

Overview:

The <object> tag is a new addition to HTML version 4. The purpose of this tag is to provide a generic tag that will handle multimedia elements (see Figure 1). Applets, images, video, and other HTML documents can all be displayed via the <object> tag. It's modular design provides many attributes to handle the different types of objects. The tag also has the possibility of being extended to handle future types of objects. The <applet> tag is deprecated for HTML 4, however is still allowed by a majority of the browsers. There are some inconsistencies in the attributes and the way they are displayed in Internet Explorer and other non-Internet Explorer browsers. Internet Explorer seems to have some "extra" attributes and won't render the objects that don't use their attributes.

Figure 1

Attributes:

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 designer should make. Only the <applet> tag should not be used since it is deprecated. The nice thing about the <object> tag is the ability to nest. This feature comes in handy when a browser cannot display the intended object. In this case, the next nested object would be executed. It's like a nested if,else programming statement.

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 probably 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 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've discovered that Opera 6 displays every object on this page and therefore makes it the most compatible HTML browser I ever used.

One great advantage of the <object> tag is the ability to declare 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 on in your HTML document.

Examples:

Keno

[Internet Explorer version]
Screen Shot
Keno 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="Keno.class"
        width="450" height="300"
        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 displays the text "Applet cannot be loaded. Not using Netscape compatible browser." This is one of the advantages of using <object> tags. This example will display an error 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.


Keno

[Netscape/Opera version]
Screen Shot
Keno 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:Keno.class"
width="450" height="300"
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 (which is a W3C standard) attribute is used for non-IE browsers and the CODE (not a W3C standard) attribute is used by IE browsers. The other difference is the way the CODEBASE attribute is specified. This example uses a relative path to 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 Keno applet should look like in an Opera browser.


Star Image

[Internet Explorer version]

Screen Shot
Image

Image cannot be found

Screen Shot
Image
[Netscape/Opera version]

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 IE 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]



ICS 415 | Topic Notes | Assignments | Feedback | Links

Last Updated: January 31, 2002