JavaScript and Embedded Objects - Plug-ins (Page 6 of 15 )
Browser plug-ins are executable components that extend the browser’s capabilities in a particular way. When the browser encounters an embedded object of a type that it is not prepared to handle (e.g., something that isn’t HTML or other Web file type), the browser might hand the content off to an appropriate plug-in. If no appropriate plug-in is installed, the user is given the option to install one (assuming the page is properly written). Plug-ins consist of executable code for displaying or otherwise processing a particular type of data. In this way, the browser is able to hand special types of data, for example multimedia files, to plug-ins for processing.
Plug-ins are persistent in the browser in the sense that once installed, they remain there unless manually removed by the user. Most browsers come with many plug-ins already installed, so you may have used them without even knowing. Plug-ins were introduced in Netscape 2 but are supported, at least HTML–syntax-wise, by most major browsers, including Opera and Internet Explorer 3 and later. However, the actual component in the case of Internet Explorer is not a plug-in but instead an ActiveX control discussed later in the chapter. Plug-ins are a Netscape-introduced technology supported by many other browsers.
Embedding Content for Plug-Ins Although never officially a part of any HTML specification, the <embed> tag is most often used to include embedded objects for Netscape and Internet Explorer. A Macromedia Flash file might be embedded as follows:
<embed id="demo" name="demo"
src="http://www.javascriptref.com/examples/ch18/flash.swf"
width="318" height="252" play="true" loop="false"
pluginspage="http://www.macromedia.com/go/getflashplayer"
swliveconnect="true"></embed>
The result of loading a page with this file is shown in Figure 18-3.
The most important attributes of the <embed> tag are src, which gives the URL of the embedded object, and pluginspage, which indicates to the browser where the required plug-in is to be found if it is not installed in the browser. Plug-in vendors typically make available the embedding syntax, so check their site for the value of pluginspage.
Recall that applets embedded with <object> tags are passed initial parameters in <param> tags. The syntax of <embed> is different in that initial parameters are passed using attributes of the element itself. For instance, in the preceding example the play attribute tells the plug-in to immediately begin playing the specified file.

FIGURE 18-3 An embedded Flash file
The <object> element is the newer, official way to include embedded objects of any kind in your pages. However, <object> is not supported in Netscape browsers prior to version 4, and <embed> continues to be supported by new browsers. So it is unlikely that <object> will completely supplant <embed> any time in the near future. However, <object> and <embed> are very often used together in order to maximize client compatibility. This technique is illustrated in the later ActiveX section of this chapter.
This chapter is from JavaScript: The Complete Reference, second edition, by Thomas Powell and Fritz Schneider, McGraw-Hill/Osborne, ISBN: 0072253576). Check it out at your favorite bookstore today.
Buy this book now. |
Next: MIME Types >>
More JavaScript Articles
More By McGraw-Hill/Osborne