Functions to Examine Browsers : Browser Info « Window Browser « JavaScript DHTML






Functions to Examine Browsers

 
/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

Publisher: John Wiley & Sons CopyRight 2001
ISBN: 0764533428
*/


<HTML>
<HEAD>
<TITLE>UserAgent Property Library</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// basic brand determination
function isNav() {
    return (navigator.appName == "Netscape")
}
function isIE() {
    return (navigator.appName == "Microsoft Internet Explorer")
}
// operating system platforms
function isWindows() {
    return (navigator.appVersion.indexOf("Win") != -1)
}
function isWin95NT() {
    return (isWindows() && (navigator.appVersion.indexOf("Win16") == -1 && 
        navigator.appVersion.indexOf("Windows 3.1") == -1))
}
function isMac() {
    return (navigator.appVersion.indexOf("Mac") != -1)
}
function isMacPPC() {
    return (isMac() && (navigator.appVersion.indexOf("PPC") != -1 || 
       navigator.appVersion.indexOf("PowerPC") != -1))
}
function isUnix() {
    return (navigator.appVersion.indexOf("X11") != -1)
}
// browser versions
function isGeneration2() {
    return (parseInt(navigator.appVersion) == 2)
}
function isGeneration3() {
    return (parseInt(navigator.appVersion) == 3)
}
function isGeneration3Min() {
    return (parseInt(navigator.appVersion.charAt(0)) >= 3)
}
function isNav4_7() {
    return (isNav() && parseFloat(navigator.appVersion) == 4.7)
}
function isMSIE4Min() {
    return (isIE() && navigator.appVersion.indexOf("MSIE") != -1)
}
function isMSIE5_5() {
    return (navigator.appVersion.indexOf("MSIE 5.5") != -1)
}
function isNN6Min() {
    return (isNav() && parseInt(navigator.appVersion) >= 5)
}
// element referencing syntax
function isDocAll() {
    return (document.all) ? true : false
}
function isDocW3C() {
    return (document.getElementById) ? true : false
}
// fill in the blanks
function checkBrowser() {
    var form = document.forms[0]
    form.brandNN.value = isNav()
    form.brandIE.value = isIE()
    form.win.value = isWindows()
    form.win32.value = isWin95NT()
    form.mac.value = isMac()
    form.ppc.value = isMacPPC()
    form.unix.value = isUnix()
    form.ver3Only.value = isGeneration3()
    form.ver3Up.value = isGeneration3Min()
    form.Nav4_7.value = isNav4_7()
    form.Nav6Up.value = isNN6Min()
    form.MSIE4.value = isMSIE4Min()
    form.MSIE5_5.value = isMSIE5_5()
    form.doc_all.value = isDocAll()

form.doc_w3c.value = isDocW3C()
}
</SCRIPT>
</HEAD>
<BODY onLoad="checkBrowser()">
<H1>About This Browser</H1>
<FORM>
<H2>Brand</H2>
Netscape Navigator:<INPUT TYPE="text" NAME="brandNN" SIZE=5>
Internet Explorer:<INPUT TYPE="text" NAME="brandIE" SIZE=5>
<HR>
<H2>Browser Version</H2>
3.0x Only (any brand):<INPUT TYPE="text" NAME="ver3Only" SIZE=5><P>
3 or Later (any brand): <INPUT TYPE="text" NAME="ver3Up" SIZE=5><P>
Navigator 4.7: <INPUT TYPE="text" NAME="Nav4_7" SIZE=5><P>
Navigator 6+: <INPUT TYPE="text" NAME="Nav6Up" SIZE=5><P>
MSIE 4+: <INPUT TYPE="text" NAME="MSIE4" SIZE=5><P>
MSIE 5.5:<INPUT TYPE="text" NAME="MSIE5_5" SIZE=5><P>
<HR>
<H2>OS Platform</H2>
Windows: <INPUT TYPE="text" NAME="win" SIZE=5>
Windows 95/98/2000/NT: <INPUT TYPE="text" NAME="win32" SIZE=5><P>
Macintosh: <INPUT TYPE="text" NAME="mac" SIZE=5>
Mac PowerPC: <INPUT TYPE="text" NAME="ppc" SIZE=5><P>
Unix: <INPUT TYPE="text" NAME="unix" SIZE=5><P>
<HR>
<H2>Element Referencing Style</H2>
Use <TT>document.all</TT>: <INPUT TYPE="text" NAME="doc_all" SIZE=5><P>
Use <TT>document.getElementById()</TT>: <INPUT TYPE="text" NAME="doc_w3c"
 SIZE=5><P>
</FORM>
</BODY>
</HTML>


           
         
  








Related examples in the same category

1.Detects the browser, its version and the operating system of the client
2.Detects the language used by the client's browser
3.Indentify your browser
4.Navigator:detect the client's browser
5.More details about the client's browser
6.All details about the client's browser
7.Browser infomation
8.Accessing the Properties of the navigator Object
9.Writing Different Text to a Page Based on the Browser
10. Navigator Object
11.Using Navigator Properties
12.Get Browser version
13.Methods and Properties of the Frame Object
14.The Methods and Properties of the navigator Object
15.Verify browser language
16.Is cookie Enabled
17.document.alinkColor
18.document.lastModified
19.document.title
20.document.bgColor
21.document.fgColor
22.document.linkColor
23.document.vlinkColor