The Navigator object, which was first introduced by Netscape Navigator 2.0, has now become the de facto standard for identifying client browsers. While other browsers provide the same or similar information by other means (for example, Window.clientinformation in IE and Window.opera in opera), but navigator objects are common to all JavaScript-enabled browsers. As with other BOM objects, navigator objects in each browser have their own properties. The following table lists the properties and methods that exist in all browsers, as well as the browser versions that support them.
property or Method |
Description |
IE |
FireFox |
Safari/chrome |
Opera |
appCodeName |
Returns the name of the browser, usually Mozilla, even in non-Mozilla browsers |
3.0+ |
1.0+ |
1.0+ |
7.0+ |
appMinorVersion |
Minor version information |
4.0+ |
- |
- |
9.5+ |
appName |
Full Browser name |
3.0+ |
1.0+ |
1.0+ |
7.0+ |
appVersion |
Browser version, generally not corresponding to the actual browser version |
3.0+ |
1.0+ |
1.0+ |
7.0+ |
Buildid |
The compiled version of the browser |
- |
2.0+ |
- |
- |
cookieEnabled |
Indicates whether the cookie is enabled |
4.0+ |
1.0+ |
1.0+ |
7.0+ |
Cpuclass |
CPU type used in client computers (x86, 68K, Alpha, PPC, or other) |
4.0+ |
- |
- |
- |
javaEnabled |
Indicates whether Java is enabled in the current browser |
4.0+ |
1.0+ |
1.0+ |
7.0+ |
Language |
Main language of the browser |
- |
1.0+ |
1.0+ |
7.0+ |
mimeType |
An array of MIME types registered in the browser |
4.0+ |
1.0+ |
1.0+ |
7.0+ |
OnLine |
Indicates whether the browser is connected to the Internet |
4.0+ |
1.0+ |
- |
9.5+ |
Opsprofile |
It doesn't seem to be a long time. Documents not found |
4.0+ |
- |
- |
- |
Oscpu |
The operating system or CPU used by the client computer |
- |
1.0+ |
- |
- |
platform |
The system platform on which the browser resides |
4.0+ |
1.0+ |
1.0+ |
7.0+ |
plugins |
An array of plug-in information installed in the browser |
4.0+ |
1.0+ |
1.0+ |
7.0+ |
Preference () |
Set the user's preferences |
- |
1.5+ |
- |
- |
Product |
Product name (e.g. Gecko) |
- |
1.0+ |
1.0+ |
- |
Productsub |
Minor information about the product (such as the version of Gecko) |
- |
1.0+ |
1.0+ |
- |
Registercontenthandler () |
Registering a site as a handler for a specific MIME type |
- |
2.0 |
- |
- |
Registerprotocolhandler () |
Registering a site as a handler for a specific protocol |
- |
2.0 |
- |
- |
SecurityPolicy |
has been abandoned. The name of the security policy. reserved for backwards compatibility with Netscape Navigator 4 |
- |
1.0+ |
- |
- |
Systemlanguage |
The language of the operating system |
4.0+ |
- |
- |
- |
taintenabled |
has been abandoned. Indicates whether the variable is allowed to be modified (taint). reserved for backwards compatibility with Netscape Navigator 3 |
4.0+ |
1.0+ |
- |
7.0+ |
userAgent |
User agent string for the browser |
3.+ |
1.0+ |
1.0+ |
7.0+ |
Userlanguage |
Default language for the operating system |
4.0+ |
- |
- |
7.0+ |
UserProfile |
The object through which the user's personal information is accessed |
4.0+ |
- |
- |
- |
Vendor |
The brand of the browser |
- |
1.0+ |
1.0+ |
- |
Vendorsub |
Secondary information about the vendor |
- |
1.0+ |
1.0+ |
- |
The properties of these navigator objects in the table are typically used to detect the browser type that displays the Web page.
Detecting Plug-ins
Detecting whether a particular plug-in is installed in the browser is one of the most common check routines. For non-IE browsers you can use the plugins array to achieve this. Each item in the array contains the following properties.
Name: Plugin Name
Description: Description of the plugin
FileName: The file name of the plugin
Length: Number of MIME types processed by the plugin
In general, the name attribute contains all the information necessary to detect the plug-in, but sometimes it is not. When detecting plug-ins, you need to iterate through each plug-in as follows and compare the name of the plug-in with the given name.
1 /**2 * Detects if the plugin exists in the browser (not valid in IE)3 * @param plugin name name4 * @return Boolean exists plug-in returns True, otherwise returns false5 */6 functionHasplugin (name) {7Name =name.tolowercase ();8 for(vari = 0; i < navigator.plugins.length; i++) {9 if(Navigator.plugins[i].name.tolowercase (). IndexOf (name) >-1) {Ten return true; One } A } - return false; -}
And the detection of plug-ins in IE is troublesome, because IE does not support Netscape-style plug-ins. The only way to detect plug-ins in IE is to use a proprietary ActiveXObject type and try to create an instance of a particular plug-in. IE is implemented as a COM object, and the COM object is identified by a unique identifier. Therefore, to check a particular plug-in, you must know its COM identifier. For example, the identifier for Flash is Shockwaveflash.shockwaveflash. Once you know the unique identifier, you can write a function like the following to detect if the appropriate plug-in is installed in IE.
1 /**2 * Detection of plugins in IE3 * @param plugin name name4 * @return Boolean exists plug-in returns True, otherwise returns false5 */6 functionHasieplugin (name) {7 Try {8 NewActiveXObject (name);9 return true;Ten}Catch(ex) { One return false; A } -}
Since the methods used to detect these two plug-ins are too different, it is a typical practice to create a detection function for each plug-in, rather than using the generic detection method described earlier. Take a look at the following example.
1 /**2 * Detects if the plugin exists in the browser (not valid in IE)3 * @param plugin name name4 * @return Boolean exists plug-in returns True, otherwise returns false5 */6 functionHasplugin (name) {7Name =name.tolowercase ();8 for(vari = 0; i < navigator.plugins.length; i++) {9 if(Navigator.plugins[i].name.tolowercase (). IndexOf (name) >-1) {Ten return true; One } A } - return false; - } the - /** - * Detection of plugins in IE - * @param plugin name name + * @return Boolean exists plug-in returns True, otherwise returns false - */ + functionHasieplugin (name) { A Try { at NewActiveXObject (name); - return true; -}Catch(ex) { - return false; - } - } in - //detect flash in all browsers to functionHasflash () { + //return Hasplugin ("Flash") | | hasieplugin ("Shockwaveflash.shockwaveflash"); - varresult = Hasplugin ("Flash"); the if(!result) { *result = Hasieplugin ("Shockwaveflash.shockwaveflash"); $ }Panax Notoginseng returnresult; - } the + //detect QuickTime in all browsers A functionHasquicktime () { the //return Hasplugin ("QuickTime") | | hasieplugin ("quicktime.quicktime"); + varresult = Hasplugin ("QuickTime"); - if(!result) { $Reseult = Hasieplugin ("Quicktime.quicktime"); $ } - returnresult; - } the -Alert (Hasflash ());//detect if the browser has a flash pluginWuyiAlert (Hasquicktime ())//detect if the browser has a QuickTime plugin
(Note: This digest is from: JavaScript Advanced Programming, 3rd edition, chapter 8th, 8.3 Navigator Object p210)
Navigator,js Detection Browser Plugin