About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets


Browser Name

Question: How do I detect the browser name (vendor)?

Answer: To distinguish between the two major browsers, you can use the navigator.appName property. For Netscape browsers, the value of navigator.appName is the string "Netscape". For Microsoft Internet Explorer browsers, the value of navigator.appName is "Microsoft Internet Explorer"

Thus, to implement a Netscape/Microsoft code fork, you can use the following combination of conditional operators:

if (navigator.appName=="Netscape") {
 // Netscape-specific code goes here
}
if ((navigator.appName).indexOf("Microsoft")!=-1) {
 // Internet Explorer-specific code goes here
}
Note, however, that for compatibility with Netscape Navigator, Opera browsers also return the string "Netscape" as the value of navigator.appName. To distinguish between genuine Netscape browsers and Opera, you can use the navigator.userAgent property: the value of navigator.userAgent contains a substring "Opera" only for Opera browsers.

The code below implements the Netscape/Opera/Microsoft browser detection:

document.write('navigator.appName = '+navigator.appName+'<br>')
document.write('navigator.userAgent = '+navigator.userAgent+'<br>')

if ((navigator.userAgent).indexOf("Opera")!=-1) {
 document.write("You are using an Opera browser.")
}
else if (navigator.appName=="Netscape") {
 document.write("You are using a Netscape browser.")
}
else if ((navigator.appName).indexOf("Microsoft")!=-1) {
 document.write("You are using Microsoft Internet Explorer.")
}

In your browser, this code produces the following output:

BackBack