Java Reference
In-Depth Information
Fortunately, as you'll see, using ActiveX controls is similar to using plug-ins in other browsers, and with
a few tweaks can be done with almost the same code. The main difference is actually making sure that
the plug-in or ActiveX control is available for use and ready to run in the user's browser in the fi rst place.
This problem is covered in more detail for Firefox and IE before going on to discuss using the plug-ins
and ActiveX controls.
Checking for and Embedding Plug-ins
(Non-IE Browsers)
It's nice to create a script to use a specifi c plug-in for the web page experience of a lifetime, but unless
the visitor to your web page also has the same plug-in installed on their computer, their experience of
the web page is going to be one full of bugs and error messages. It is therefore important that you not
only correctly add the HTML required to use the plug-in in your page but also use JavaScript to check if
the user's browser has the plug-in installed that your page makes use of. You look at both these topics
in this section.
Even though this section focuses on Firefox, the same principles can be applied to Safari, Opera, and
Chrome.
Adding a Plug-in to the Page
To make use of a plug-in that is installed in the user's browser, you need to use HTML to tell the browser
where and when in your page you want to use it. This process is called embedding the plug-in.
In Firefox, the key to embedding plug-ins is the non-standard <embed/> element. This inserts the vis-
ible interface, if any, of the plug-in at that point in the page. The <embed/> element supports a number
of general attributes applicable to all plug-ins, such as height, width, pluginspage, src, and type.
You'll look at the last two of these attributes, src and type, in more detail here. You will also look at
the pluginspage attribute in the next section.
Most plug-ins display content that is stored on a web server. For example, a plug-in for sound, such as
QuickTime player, will play music from a fi le with a variety of extensions, notably the .mp3 and .aac
extensions, and the Flash plug-in will play Flash movies (fi les with the .swf extension). The <embed/>
element's src attribute enables you to specify the initial fi le for the plug-in to load and play. This will be
a URL pointing to the fi le, usually hosted on the same web server as the HTML page. It's from this fi le
that the browser determines what sort of plug-in is required. For example, if the src is http://www
.myserver.com/myflashmovie.swf, then by checking the type of the fi le, the browser can see that a
Flash player plug-in needs to be used.
However, not all plug-ins require data from an external source and therefore a value for the src attri-
bute. In such situations, how can the browser tell what plug-in to load? Well, that's where the <embed/>
element's type attribute comes in. The actual value for the type attribute will be specifi c to the plug-in.
You can fi nd out this information by typing about:plugins in the location bar. The plug-in informa-
tion loads into the browser, as shown in Figure 13-2.
Search WWH ::




Custom Search