Java Reference
In-Depth Information
Checking for and Installing Plug-ins
After you decide what type of plug-in you want to embed into the page, what happens if the browser
fi nds that this particular plug-in does not exist on the user's computer?
To solve this problem you can set the pluginspage attribute of <embed/> to point to a URL on the
plug-in creator's page. If the plug-in is not on the user's computer, a link to the URL specifi ed in the
pluginspage attribute will be displayed within the web page. The user can click the link and load
the plug-in so that your web page will function properly.
For example, with Flash the value for the pluginspage attribute needed is this:
http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash
However, if the user doesn't have the plug-in installed, you might prefer to send them to a version of
your web site that doesn't rely on that plug-in. How do you know whether a plug-in is installed?
The navigator object, introduced in Chapter 6, has a property called plugins, which is a collection
of Plugin objects, one for each plug-in installed on that browser. You can access a Plugin object in the
plugins array either by using an index value that indexes all the plug-ins installed on the user's
browser or by using the name of the plug-in application.
Internet Explorer has a navigator.plugins collection, but it is always empty.
Each Plugin object has four properties: description, filename, length, and name. You can fi nd
these values by viewing the plug-ins information page that you saw earlier.
Let's use Flash as an example. Type about:plugins in the location bar and press enter. Figure 13-3 shows
the Installed plug-ins page in Chrome, but this page remains largely the same for all non-IE browsers.
Flash has “Shockwave Flash” as its name property. The filename and description properties have
obvious meanings. The length property gives the number of MIME types supported by the plug-in.
As mentioned earlier, the name property can be used to reference the Plugin object in the plugins
array. So, the following code will set the variable shockWavePlugin to the Plugin object for Flash, if
it's installed:
var shockWavePlugIn = navigator.plugins[“Shockwave Flash”];
If it's not, navigator.plugins[“Shockwave Flash”] will return as undefined.
You can use the following to redirect users on browsers that do not have installed the plug-in you need:
if (navigator.plugins[“Shockwave Flash”])
{
window.location.replace(“my_flash_enabled_page.htm”);
}
else
{
window.location.replace(“my_non_flash_page.htm”);
}
Search WWH ::




Custom Search