JavaScript DHTML/Window Browser/Browser Info
Содержание
- 1 Accessing the Properties of the navigator Object
- 2 All details about the client"s browser
- 3 Browser infomation
- 4 Detects the browser, its version and the operating system of the client
- 5 Detects the language used by the client"s browser
- 6 document.alinkColor
- 7 document.bgColor
- 8 document.fgColor
- 9 document.lastModified
- 10 document.linkColor
- 11 document.title
- 12 document.vlinkColor
- 13 Functions to Examine Browsers
- 14 Get Browser version
- 15 Indentify your browser
- 16 Is cookie Enabled
- 17 Methods and Properties of the Frame Object
- 18 More details about the client"s browser
- 19 Navigator:detect the client"s browser
- 20 Navigator Object
- 21 The Methods and Properties of the navigator Object
- 22 Using Navigator Properties
- 23 Verify browser language
- 24 Writing Different Text to a Page Based on the Browser
<html>
<head>
<title>JavaScript Unleashed</title>
</head>
<body>
<script language="JavaScript">
<!--
document.write("navigator.appCodeName: ".bold() + navigator.appCodeName+ "<br>");
document.write("navigator.appName: ".bold() + navigator.appName + "<br>");
document.write("navigator.appVersion: ".bold() + navigator.appVersion + "<br>");
document.write("navigator.language: ".bold() + navigator.language + "<br>");
document.write("navigator.mimeTypes: ".bold() + navigator.mimeTypes + "<br>");
document.write("navigator.platform: ".bold() + navigator.platform + "<br>");
document.write("navigator.plugins: ".bold() + navigator.plugins + "<br>");
document.write("navigator.userAgent: ".bold() + navigator.userAgent + "<br>");document.close();
//--->
</script>
</body>
</html>
All details about the client"s browser
<html>
<body>
<script type="text/javascript">
var x = navigator
document.write("CodeName=" + x.appCodeName)
document.write("<br>")
document.write("MinorVersion=" + x.appMinorVersion)
document.write("<br>")
document.write("Name=" + x.appName)
document.write("<br>")
document.write("Version=" + x.appVersion)
document.write("<br>")
document.write("CookieEnabled=" + x.cookieEnabled)
document.write("<br>")
document.write("CPUClass=" + x.cpuClass)
document.write("<br>")
document.write("OnLine=" + x.onLine)
document.write("<br>")
document.write("Platform=" + x.platform)
document.write("<br>")
document.write("UA=" + x.userAgent)
document.write("<br>")
document.write("BrowserLanguage=" + x.browserLanguage)
document.write("<br>")
document.write("SystemLanguage=" + x.systemLanguage)
document.write("<br>")
document.write("UserLanguage=" + x.userLanguage)
</script>
</body>
</html>
Browser infomation
<html>
<HEAD>
<title>Browser infomation</title>
<SCRIPT>
document.write("Browser: " + navigator.appName);
document.write("<br>Version: " + navigator.appVersion);
document.write("<br>Codename: " + navigator.appCodeName);
document.write("<br>Language: " + navigator.language);
document.write("<br>Platform: " + navigator.platform);
document.write("<br>Plugins:");
for (i=0; i<navigator.plugins.length;i++){
document.write("<br> \; " + navigator.plugins[i].name);
}
document.write("<br><br>User Agent: " + navigator.userAgent);
document.write("<br>Java Enabled: " + navigator.javaEnabled());
document.write("<br>URL: " + document.location.href);
document.write("<br>Title: " + document.title);
document.write("<br>Referrer: " + document.referrer);
document.write("<br>Host: " + location.host);
document.write("<br>Host Name: " + location.hostname);
document.write("<br>Path Name: " + location.pathname);
document.write("<br>Port: " + location.port);
</SCRIPT>
</HEAD>
<BODY>
</body></HTML>
Detects the browser, its version and the operating system of the client
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>JsLib 1.3 - Exemple - navig.js</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Etienne CHEVILLARD">
<!-- navig.js -->
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
/* navig.js
* Role : detecte le navigateur et le systeme d"exploitation du client
* Projet : JsLib
* Auteur : Etienne CHEVILLARD (echevillard@users.sourceforge.net)
* Version : 1.3
* Creation : 05/04/2001
* Mise a jour : 23/02/2005
* Bogues connues : - impossible de connaitre le systeme avec Sun HotJava
*
* Detection du navigateur et de l"OS basee sur :
* JavaScript Browser Sniffer
* Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
* see http://www.webreference.ru/ for more information
*/
// --- Variables globales ---
// recupere les informations sur le navigateur
var navig_agt=navigator.userAgent.toLowerCase();
var navig_min=navig_extVer(navigator.appVersion);
var navig_maj=parseInt(navig_min);
// detecte le navigateur installe
var navig_mos=(navig_agt.indexOf("ncsa")!=-1);
var navig_omn=(navig_agt.indexOf("omniweb")!=-1);
var navig_saf=((navig_agt.indexOf("safari")!=-1) && (navig_agt.indexOf("mac")!=-1));
var navig_kqr=(navig_agt.indexOf("konqueror")!=-1);
var navig_fox=(navig_agt.indexOf("firefox")!=-1);
var navig_moz=(!navig_saf && (navig_agt.indexOf("mozilla")!=-1)
&& (navig_agt.indexOf("gecko")!=-1) && (navig_agt.indexOf("netscape")==-1));
var navig_nn=(!navig_moz && (navig_agt.indexOf("mozilla")!=-1)
&& (navig_agt.indexOf("spoofer")==-1) && (navig_agt.indexOf("compatible")==-1)
&& (navig_agt.indexOf("opera")==-1) && (navig_agt.indexOf("webtv")==-1)
&& (navig_agt.indexOf("hotjava")==-1));
var navig_nn2=(navig_nn && (navig_maj<3));
var navig_nn3=(navig_nn && (navig_maj==3));
var navig_nn4=(navig_nn && (navig_maj==4));
var navig_nn6=(navig_nn && (navig_agt.indexOf("netscape6/")!=-1));
var navig_nn7=(navig_nn && (navig_agt.indexOf("netscape/7")!=-1));
var navig_ie=((navig_agt.indexOf("msie")!=-1) && (navig_agt.indexOf("opera")==-1));
var navig_ie3=(navig_ie && (navig_maj<4));
var navig_ie4=(navig_ie && (navig_maj==4) && (navig_agt.indexOf("msie 5.")==-1)
&& (navig_agt.indexOf("msie 6.")==-1));
var navig_ie5=(navig_ie && (navig_agt.indexOf("msie 5.")!=-1));
var navig_ie6=(navig_ie && (navig_agt.indexOf("msie 6.")!=-1));
var navig_op=(navig_agt.indexOf("opera")!=-1);
var navig_op2=((navig_agt.indexOf("opera 2")!=-1) || (navig_agt.indexOf("opera/2")!=-1));
var navig_op3=((navig_agt.indexOf("opera 3")!=-1) || (navig_agt.indexOf("opera/3")!=-1));
var navig_op4=((navig_agt.indexOf("opera 4")!=-1) || (navig_agt.indexOf("opera/4")!=-1));
var navig_op5=((navig_agt.indexOf("opera 5")!=-1) || (navig_agt.indexOf("opera/5")!=-1));
var navig_op6=((navig_agt.indexOf("opera 6")!=-1) || (navig_agt.indexOf("opera/6")!=-1));
var navig_op7=((navig_agt.indexOf("opera 7")!=-1) || (navig_agt.indexOf("opera/7")!=-1));
var navig_hot=(navig_agt.indexOf("hotjava")!=-1);
var navig_hot3=(navig_hot && (navig_maj==3));
// detecte la version de Javascript
var navig_js="1.0";
if (navig_nn3 || navig_op) navig_js="1.1";
if (navig_ie4 || (navig_nn4 && (navig_min<=4.05))) navig_js="1.2";
if (navig_ie5 || navig_ie6 || navig_op5 || navig_op6 || (navig_nn4 && (navig_min>4.05))) navig_js="1.3";
if (navig_hot3 || (navig_ie5 && (navig_agt.indexOf("mac")!=-1))) navig_js="1.4";
if (navig_nn6 || navig_nn7 || navig_moz || navig_fox || navig_omn || navig_op7 || navig_saf || navig_kqr) navig_js="1.5";
// detecte le systeme installe
var navig_w23=((navig_agt.indexOf("windows nt 5.2")!=-1) || (navig_agt.indexOf("windows 2003")!=-1));
var navig_wxp=((navig_agt.indexOf("windows nt 5.1")!=-1) || (navig_agt.indexOf("windows xp")!=-1));
var navig_w2k=((navig_agt.indexOf("windows nt 5.0")!=-1) || (navig_agt.indexOf("windows 2")!=-1));
var navig_wnt=((navig_agt.indexOf("winnt")!=-1) || (navig_agt.indexOf("windows nt")!=-1));
var navig_wme=(navig_agt.indexOf("win 9x 4.90")!=-1);
var navig_w98=((navig_agt.indexOf("win98")!=-1) || (navig_agt.indexOf("windows 98")!=-1));
var navig_w95=((navig_agt.indexOf("win95")!=-1) || (navig_agt.indexOf("windows 95")!=-1)
|| (navig_agt.indexOf("win")!=-1) || (navig_agt.indexOf("32bit")!=-1));
var navig_w31=((navig_agt.indexOf("win16")!=-1) || (navig_agt.indexOf("16bit")!=-1)
|| (navig_agt.indexOf("windows 3.1")!=-1) || (navig_agt.indexOf("windows 16-bit")!=-1));
var navig_os2=((navig_agt.indexOf("os/2")!=-1) || (navig_agt.indexOf("ibm-webexplorer")!=-1)
|| (navigator.appVersion.indexOf("OS/2")!=-1));
var navig_macx=(navig_omn || (navig_agt.indexOf("mac os x")!=-1));
var navig_mac=(navig_agt.indexOf("mac")!=-1);
var navig_sun=(navig_agt.indexOf("sunos")!=-1);
var navig_irix=(navig_agt.indexOf("irix")!=-1);
var navig_hpux=(navig_agt.indexOf("hp-ux")!=-1);
var navig_aix=(navig_agt.indexOf("aix")!=-1);
var navig_linux=((navig_agt.indexOf("linux")!=-1) || (navig_agt.indexOf("x11")!=-1));
var navig_sco=((navig_agt.indexOf("sco")!=-1) || (navig_agt.indexOf("unix_sv")!=-1));
var navig_ware=((navig_agt.indexOf("unix_system_v")!=-1) || (navig_agt.indexOf("unixware")!=-1));
var navig_open=((navig_agt.indexOf("openunix")!=-1) || (navig_agt.indexOf("open unix")!=-1));
var navig_mpras=(navig_agt.indexOf("ncr")!=-1);
var navig_dec=((navig_agt.indexOf("dec")!=-1) || (navig_agt.indexOf("osf1")!=-1)
|| (navig_agt.indexOf("alpha")!=-1) || (navig_agt.indexOf("ultrix")!=-1));
var navig_tru=(navig_agt.indexOf("tru64")!=-1);
var navig_sinix=(navig_agt.indexOf("sinix")!=-1);
var navig_fbsd=(navig_agt.indexOf("freebsd")!=-1);
var navig_nbsd=(navig_agt.indexOf("netbsd")!=-1);
var navig_obsd=(navig_agt.indexOf("openbsd")!=-1);
var navig_bsd=(navig_agt.indexOf("bsd")!=-1);
var navig_beos=(navig_agt.indexOf("beos")!=-1);
var navig_qnx=(navig_agt.indexOf("qnx")!=-1);
// --- Fonctions ---
// extrait le numero de version d"une portion de texte
function navig_extVer(txt) {
if (!txt) return "";
var ver="";
for(var i=0; i<txt.length; i++) {
if ((isNaN(txt.charAt(i))) && (txt.charAt(i)!=".")) {
if (ver.length>0) return(ver);
} else {
ver+=txt.charAt(i);
}
}
return ver;
} // fin navig_extVer(txt)
// retourne le nom du navigateur
function nomNavig() {
if (navig_mos) return ("NCSA Mosaic");
else if (navig_omn) return ("OmniWeb");
else if (navig_kqr) return ("Konqueror");
else if (navig_saf) return ("Apple Safari");
else if (navig_ie) return ("Microsoft Internet Explorer");
else if (navig_op) return ("Opera");
else if (navig_hot) return ("Sun HotJava");
else if (navig_fox) return ("Mozilla Firefox");
else if (navig_moz) return ("Mozilla");
else if (navig_nn6 || navig_nn7) return ("Netscape");
else if (navig_nn) return ("Netscape Navigator");
else return ("inconnu");
} // fin nomNavig()
// retourne le nom du systeme d"exploitation
function nomSysteme() {
if (navig_w23) return ("Microsoft Windows Server 2003");
else if (navig_wxp) return ("Microsoft Windows XP");
else if (navig_w2k) return ("Microsoft Windows 2000");
else if (navig_wnt) return ("Microsoft Windows NT 4.0");
else if (navig_wme) return ("Microsoft Windows Me");
else if (navig_w98) return ("Microsoft Windows 98");
else if (navig_w95) return ("Microsoft Windows 95");
else if (navig_w31) return ("Microsoft Windows 3.1");
else if (navig_os2) return ("IBM OS/2");
else if (navig_macx) return ("Apple MacOS X");
else if (navig_mac) return ("Apple MacOS");
else if (navig_sun) return ("Sun Solaris (SunOS)");
else if (navig_irix) return ("SGI Irix");
else if (navig_hpux) return ("HP-UX");
else if (navig_aix) return ("IBM AIX");
else if (navig_linux) return ("GNU/Linux");
else if (navig_sco) return ("SCO UNIX");
else if (navig_ware) return ("UNIXware");
else if (navig_open) return ("Caldera Open UNIX");
else if (navig_mpras) return ("NCR UNIX MPRAS");
else if (navig_dec) return ("Digital UNIX");
else if (navig_tru) return ("HP Tru64 UNIX");
else if (navig_sinix) return ("Siemens SINIX");
else if (navig_fbsd) return ("FreeBSD");
else if (navig_nbsd) return ("NetBSD");
else if (navig_obsd) return ("OpenBSD");
else if (navig_bsd) return ("BSD/OS");
else if (navig_beos) return ("BeOS");
else if (navig_qnx) return ("QNX");
else return ("inconnu");
} // fin nomSysteme()
// retourne le nom et la version du navigateur
function nomVersionNavig() {
if (nomNavig()=="inconnu") {
return (nomNavig());
} else {
return (nomNavig()+" "+versionNavig());
}
} // fin nomVersionNavig()
// retourne la version de Javascript prise en charge par le navigateur
function versionJavascript() {
return (navig_js);
} // fin versionJavascript()
// retourne la version du navigateur
function versionNavig() {
var tmp;
if (navig_ie3 && (navig_maj<3)) {
return ("3.0");
} else if (navig_ie5 || navig_ie6) {
tmp=navig_agt.indexOf("msie");
return(navig_extVer(navig_agt.substring(tmp+5)));
} else if (navig_saf) {
tmp=parseInt(navig_agt.substring(navig_agt.indexOf("safari/")+7));
if (tmp==100) return ("1.1");
else if (tmp==125) return ("1.2");
else if (tmp==146) return ("1.3");
else if (tmp>146) return ("2.0");
else return ("1.0");
} else if (navig_kqr) {
tmp=navig_agt.indexOf("konqueror/");
return(navig_extVer(navig_agt.substring(tmp+10)));
} else if (navig_omn) {
tmp=navig_agt.indexOf("omniweb/");
return(navig_extVer(navig_agt.substring(tmp+8)));
} else if (navig_fox) {
tmp=navig_agt.indexOf("firefox/");
return(navig_extVer(navig_agt.substring(tmp+8)));
} else if (navig_moz) {
tmp=navig_agt.indexOf("rv:");
return(navig_extVer(navig_agt.substring(tmp+3)));
} else if (navig_nn6) {
tmp=navig_agt.indexOf("netscape6/");
return(navig_extVer(navig_agt.substring(tmp+10)));
} else if (navig_nn7) {
tmp=navig_agt.indexOf("netscape/");
return(navig_extVer(navig_agt.substring(tmp+9)));
} else if (nomNavig()=="inconnu") {
return ("inconnu");
} else {
return (navig_min);
}
} // fin versionNavig()
</SCRIPT>
</HEAD>
<BODY>
<H1>JsLib 1.3</H1>
<HR>
<H2>Exemple - navig.js</H2>
<NOSCRIPT>
<P><I>Erreur : votre navigateur ne reconnait pas le Javascript ou est configuré pour ne
pas prendre en compte le code Javascript. Dans ce dernier cas, vous pouvez modifier la
configuration dans les préférences/options de votre navigateur.</I>
<HR>
</NOSCRIPT>
<P>Nom de votre navigateur :
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">document.write(nomNavig());</SCRIPT>
<P>Nom et version de votre navigateur :
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">document.write(nomVersionNavig());</SCRIPT>
<P>Version de Javascript reconnue par votre navigateur :
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">document.write(versionJavascript());</SCRIPT>
<P>Nom de votre système d"exploitation :
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">document.write(nomSysteme());</SCRIPT>
</BODY>
</HTML>
Detects the language used by the client"s browser
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>JsLib 1.3 - Exemple - langue.js</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Etienne CHEVILLARD">
<!-- langue.js -->
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
/* langue.js
* Role : detecte la langue du navigateur du client
* Projet : JsLib
* Auteur : Etienne CHEVILLARD (echevillard@users.sourceforge.net)
* Version : 1.3
* Creation : 10/04/2001
* Mise a jour : 23/02/2005
*/
// --- Variables globales ---
// tableau des codes ISO
var langue_tabct=new Array("aa","ab","af","am","ar","as","ay","az","ba","be",
"bg","bh","bi","bn","bo","br","ca","co","cs","cy",
"da","de","dz","el","en","eo","es","et","eu","fa",
"fi","fj","fo","fr","fy","ga","gd","gl","gn","gu",
"gv","ha","he","hi","hr","hu","hy","ia","id","ie",
"ik","is","it","iu","ja","jw","ka","kk","kl","km",
"kn","ko","ks","ku","kw","ky","la","lb","ln","lo",
"lt","lv","mg","mi","mk","ml","mn","mo","mr","ms",
"mt","my","na","ne","nl","no","oc","om","or","pa",
"pl","ps","pt","qu","rm","rn","ro","ru","rw","sa",
"sd","se","sg","sh","si","sk","sl","sm","sn","so",
"sq","sr","ss","st","su","sv","sw","ta","te","tg",
"th","ti","tk","tl","tn","to","tr","ts","tt","tw",
"ug","uk","ur","uz","vi","vo","wo","xh","yi","yo",
"za","zh","zu");
// tableau des langues en francais
var langue_tablg=new Array("Afar","Abkhaze","Afrikaans","Amharique","Arabe",
"Assamais","Aymara","Azéri","Bachkir","Biélorusse",
"Bulgare","Bihari","Bêche-De-Mer","Bengali","Tibétain",
"Breton","Catalan","Corse","Tchèque","Gallois",
"Danois","Allemand","Boutani","Grec","Anglais",
"Espéranto","Espagnol","Estonien","Basque","Persan",
"Finnois","Fidjien","Féroïen","Français","Frison",
"Gaélique Irlandais","Gaélique Écossais","Galicien","Guarani","Goudjarati",
"Gaélique de l"Île de Man","Haoussa","Hébreu","Hindi","Croate",
"Hongrois","Arménien","Interlingua","Indonésien","Interlingue",
"Inupiak","Islandais","Italien","Inuktitut","Japonais",
"Javanais","Géorgien","Kazakh","Groenlandais","Cambodgien",
"Kannada","Coréen","Cachemiri","Kurde","Cornique",
"Kirghiz","Latin","Luxembourgeois","Lingala","Lao",
"Lithuanien","Letton","Malgache","Maori","Macédonien",
"Malayalam","Mongol","Moldave","Marathe","Malais",
"Maltais","Birman","Nauri","Népalais","Néerlandais",
"Norvégien","Occitan","Oromo","Oriya","Pendjabi",
"Polonais","Pachto","Portuguais","Quechua","Rhéto-Roman",
"Roundi","Roumain","Russe","Rouanda","Sanscrit",
"Sindhi","Sámi Du Nord","Sango","Serbo-Croate","Cingalais",
"Slovaque","Slovène","Samoan","Chona","Somali",
"Albanais","Serbe","Siswati","Sotho Du Sud","Soundanais",
"Suédois","Souahéli","Tamoul","Télougou","Tadjik",
"Thaï","Tigrigna","Turkmène","Tagal","Setchwana",
"Kitonga","Turc","Tsonga","Tatar","Tchi",
"Ouïgour","Ukrainien","Ourdou","Ouzbek","Vietnamien",
"Volapük","Ouolof","Xhosa","Yidich","Yorouba",
"Tchouang","Chinois","Zoulou");
// --- Fonctions ---
// retourne le code ISO de la langue du navigateur
function obtenirCodeLangueNavig() {
var lct="en";
if (navigator.language) {
lct=navigator.language.toLowerCase().substring(0, 2);
} else if (navigator.userLanguage) {
lct=navigator.userLanguage.toLowerCase().substring(0, 2);
} else if (navigator.userAgent.indexOf("[")!=-1) {
var debut=navigator.userAgent.indexOf("[");
var fin=navigator.userAgent.indexOf("]");
lct=navigator.userAgent.substring(debut+1, fin).toLowerCase();
}
return lct;
} // fin obtenirCodeLangueNavig()
// retourne la langue en francais correspondant au code de langue specifie
function obtenirLangue(code) {
if ((!code) || (code.length<2))
return "";
code=code.toLowerCase().substring(0, 2);
for (var i=0; i<langue_tabct.length; i++) {
if (langue_tabct[i]==code)
return(langue_tablg[i]);
}
return "";
} // fin obtenirLangue(code)
// retourne la langue du navigateur en francais
function obtenirLangueNavig() {
return (obtenirLangue(obtenirCodeLangueNavig()));
} // fin obtenirLangueNavig()
</SCRIPT>
</HEAD>
<BODY>
<H1>JsLib 1.3</H1>
<HR>
<H2>Exemple - langue.js</H2>
<NOSCRIPT>
<P><I>Erreur : votre navigateur ne reconnaît pas le Javascript ou est configuré pour ne
pas prendre en compte le code Javascript. Dans ce dernier cas, vous pouvez modifier la
configuration dans les préférences/options de votre navigateur.</I>
<HR>
</NOSCRIPT>
<P>Code de la langue de votre navigateur :
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">document.write(obtenirCodeLangueNavig())</SCRIPT>
<P>Langue de votre navigateur :
<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">document.write(obtenirLangueNavig())</SCRIPT>
<P>Langue pour un code de langue :
<FORM ACTION="GET" NAME="f">
<TABLE SUMMARY="formulaire" BORDER=0 CELLSPACING=2 CELLPADDING=2>
<TR><TD>
Code :
</TD><TD>
<INPUT NAME="t1" TYPE="text" SIZE="30" MAXLENGTH="2" VALUE="zu">
<INPUT NAME="b1" TYPE="button" VALUE="Rechercher"
onClick="this.form.t2.value=obtenirLangue(this.form.t1.value)">
</TD></TR><TR><TD>
Langue :
</TD><TD>
<INPUT NAME="t2" TYPE="text" SIZE="30" VALUE="">
</TD></TR>
</TABLE>
</FORM>
</BODY>
</HTML>
document.alinkColor
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor="beige" text= "black" link="darkblue" vlink="honeydew">
<SCRIPT language="JavaScript">
document.write("<H1>"+document.title+"</H1>");
document.write("The background color is "+document.bgColor+"<BR>");
document.write("The text color is "+document.fgColor+"<BR>");
document.write("The link color is "+document.linkColor+"<BR>");
document.write("The visited link color is "+document.vlinkColor+"<BR>");
document.write("The active link color is "+document.alinkColor+"<BR>");
document.write("Last Modified: "+document.lastModified+"<BR>");
document.write("URL: "+document.URL);
</SCRIPT>
</BODY>
</HTML>
document.bgColor
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor="beige" text= "black" link="darkblue" vlink="honeydew">
<SCRIPT language="JavaScript">
document.write("<H1>"+document.title+"</H1>");
document.write("The background color is "+document.bgColor+"<BR>");
document.write("The text color is "+document.fgColor+"<BR>");
document.write("The link color is "+document.linkColor+"<BR>");
document.write("The visited link color is "+document.vlinkColor+"<BR>");
document.write("The active link color is "+document.alinkColor+"<BR>");
document.write("Last Modified: "+document.lastModified+"<BR>");
document.write("URL: "+document.URL);
</SCRIPT>
</BODY>
</HTML>
document.fgColor
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor="beige" text= "black" link="darkblue" vlink="honeydew">
<SCRIPT language="JavaScript">
document.write("<H1>"+document.title+"</H1>");
document.write("The background color is "+document.bgColor+"<BR>");
document.write("The text color is "+document.fgColor+"<BR>");
document.write("The link color is "+document.linkColor+"<BR>");
document.write("The visited link color is "+document.vlinkColor+"<BR>");
document.write("The active link color is "+document.alinkColor+"<BR>");
document.write("Last Modified: "+document.lastModified+"<BR>");
document.write("URL: "+document.URL);
</SCRIPT>
</BODY>
</HTML>
document.lastModified
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor="beige" text= "black" link="darkblue" vlink="honeydew">
<SCRIPT language="JavaScript">
document.write("<H1>"+document.title+"</H1>");
document.write("The background color is "+document.bgColor+"<BR>");
document.write("The text color is "+document.fgColor+"<BR>");
document.write("The link color is "+document.linkColor+"<BR>");
document.write("The visited link color is "+document.vlinkColor+"<BR>");
document.write("The active link color is "+document.alinkColor+"<BR>");
document.write("Last Modified: "+document.lastModified+"<BR>");
document.write("URL: "+document.URL);
</SCRIPT>
</BODY>
</HTML>
document.linkColor
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor="beige" text= "black" link="darkblue" vlink="honeydew">
<SCRIPT language="JavaScript">
document.write("<H1>"+document.title+"</H1>");
document.write("The background color is "+document.bgColor+"<BR>");
document.write("The text color is "+document.fgColor+"<BR>");
document.write("The link color is "+document.linkColor+"<BR>");
document.write("The visited link color is "+document.vlinkColor+"<BR>");
document.write("The active link color is "+document.alinkColor+"<BR>");
document.write("Last Modified: "+document.lastModified+"<BR>");
document.write("URL: "+document.URL);
</SCRIPT>
</BODY>
</HTML>
document.title
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor="beige" text= "black" link="darkblue" vlink="honeydew">
<SCRIPT language="JavaScript">
document.write("<H1>"+document.title+"</H1>");
document.write("The background color is "+document.bgColor+"<BR>");
document.write("The text color is "+document.fgColor+"<BR>");
document.write("The link color is "+document.linkColor+"<BR>");
document.write("The visited link color is "+document.vlinkColor+"<BR>");
document.write("The active link color is "+document.alinkColor+"<BR>");
document.write("Last Modified: "+document.lastModified+"<BR>");
document.write("URL: "+document.URL);
</SCRIPT>
</BODY>
</HTML>
document.vlinkColor
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor="beige" text= "black" link="darkblue" vlink="honeydew">
<SCRIPT language="JavaScript">
document.write("<H1>"+document.title+"</H1>");
document.write("The background color is "+document.bgColor+"<BR>");
document.write("The text color is "+document.fgColor+"<BR>");
document.write("The link color is "+document.linkColor+"<BR>");
document.write("The visited link color is "+document.vlinkColor+"<BR>");
document.write("The active link color is "+document.alinkColor+"<BR>");
document.write("Last Modified: "+document.lastModified+"<BR>");
document.write("URL: "+document.URL);
</SCRIPT>
</BODY>
</HTML>
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>
Get Browser version
<HTML>
<HEAD>
</head>
<body>
<script LANGUAGE="JavaScript">
<!-- hide from old browsers
document.write("This browser is version " + navigator.appVersion)
document.write(" of <B>" + navigator.appName + "</B>.")
// end script hiding -->
</SCRIPT>
</body>
</HTML>
Indentify your browser
<html>
<body>
<h1>Welcome!</h1>
<hr>
<p>Your browser identifies itself to the server as:<br>
<script language="JavaScript" type="text/javascript">
document.write(navigator.userAgent + ".");
</script>
</p>
</body>
</html>
Is cookie Enabled
if (navigator.cookieEnabled) {
// invoke cookie statements here
}
Methods and Properties of the Frame Object
Method blur() Removes focus from the frame.
clearInterval() Cancels a repeated execution.
clearTimeout() Cancels any delayed execution.
focus() Applies focus to a frame.
print() Invokes the Print dialog box.
setInterval() Sets function schedule for repeated execution.
setTimeout() Sets function schedule for delayed execution.
Property
document Current document loaded within a frame.
frames Array containing references to child frames.
length Length of the frames array.
name name attribute of the frame tag.
parent Main window or frame from which child frames are created.
self Refers to the current frame.
top Browser window that executes script.
window Refers to current window or frame.
More details about the client"s browser
<html>
<body>
<script type="text/javascript">
document.write("<p>Browser: ")
document.write(navigator.appName + "</p>")
document.write("<p>Browserversion: ")
document.write(navigator.appVersion + "</p>")
document.write("<p>Code: ")
document.write(navigator.appCodeName + "</p>")
document.write("<p>Platform: ")
document.write(navigator.platform + "</p>")
document.write("<p>Cookies enabled: ")
document.write(navigator.cookieEnabled + "</p>")
document.write("<p>Browser"s user agent header: ")
document.write(navigator.userAgent + "</p>")
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
document.write("You are browsing this site with: "+ navigator.appName)
</script>
</body>
</html>
<HTML>
<HEAD>
<SCRIPT LANGUAGE = "JavaScript">
function displayBrowserInfo() {
var browserStr = ""
browserStr += "Browser: " + navigator.appName + "\r"
browserStr += "Version:" + navigator.appVersion + "\r"
browserStr += "Codename: " + navigator.appCodeName + "\r"
browserStr += "User agent: " + navigator.userAgent + "\r"
alert(browserStr)
}
</SCRIPT>
<BODY>
<H1></H1>
<FORM>
<INPUT Type="button" Value="Show Browser Information" OnClick="displayBrowserInfo()"
</INPUT>
</FORM>
</BODY>
</HTML>
Method javaEnabled() :If Java is supported in the browser.
plugins.refresh() :Checks for any newly installed plug-ins.
preference() :Allows reading and setting of various user preferences.
taintEnabled() :Tests to see if data-tainting is enabled.
Property appCodeName: Represents the code name of the browser.
appName : Refers to the official browser name.
appVersion : Refers to the version information of the browser.
language : Refers to the language of the browser.
mimeTypes : Refers to an array of Mimetype objects that the browser supports.
platform : A string representing the platform.
plugins : Refers to an array of Plugin objects installed on the browser.
userAgent : A string that represents the user-agent header.
<HTML>
<HEAD>
<TITLE>Detecting Browser Capabilities</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function displayNavigatorProperties() {
with(document) {
write("<B>appName: </B>")
writeln(navigator.appName+"<BR>")
write("<B>appVersion: </B>")
writeln(navigator.appVersion+"<BR>")
write("<B>appCodeName: </B>")
writeln(navigator.appCodeName+"<BR>")
write("<B>platform: </B>")
writeln(navigator.platform+"<BR>")
write("<B>userAgent: </B>")
writeln(navigator.userAgent+"<BR>")
write("<B>language: </B>")
writeln(navigator.language+"<BR>")
write("<B>Number of mimeTypes: </B>")
writeln(navigator.mimeTypes.length+"<BR>")
write("<B>Number of plugins: </B>")
writeln(navigator.plugins.length)
}
}
function displayExplorerProperties() {
with(document) {
write("<B>appName: </B>")
writeln(navigator.appName+"<BR>")
write("<B>appVersion: </B>")
writeln(navigator.appVersion+"<BR>")
write("<B>appMinorVersion: </B>")
writeln(navigator.appMinorVersion+"<BR>")
write("<B>appCodeName: </B>")
writeln(navigator.appCodeName+"<BR>")
write("<B>platform: </B>")
writeln(navigator.platform+"<BR>")
write("<B>cpuClass: </B>")
writeln(navigator.cpuClass+"<BR>")
write("<B>userAgent: </B>")
writeln(navigator.userAgent+"<BR>")
write("<B>cookieEnabled: </B>")
writeln(navigator.cookieEnabled+"<BR>")
write("<B>browserLanguage: </B>")
writeln(navigator.browserLanguage+"<BR>")
write("<B>userLanguage: </B>")
writeln(navigator.userLanguage+"<BR>")
write("<B>systemLanguage: </B>")
writeln(navigator.systemLanguage+"<BR>")
write("<B>onLine: </B>")
writeln(navigator.onLine+"<BR>")
write("<B>Number of mimeTypes: </B>")
writeln(navigator.mimeTypes.length+"<BR>")
write("<B>Number of plugins: </B>")
writeln(navigator.plugins.length+"<BR>")
write("<B>userProfile: </B>")
writeln(navigator.userProfile)
}
}
function displayBrowserProperties() {
if(navigator.appName=="Netscape")
displayNavigatorProperties()
else
if(navigator.appName=="Microsoft Internet Explorer")
displayExplorerProperties()
}
displayBrowserProperties()
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
Verify browser language
<!--
Example File From "JavaScript and DHTML Cookbook"
Published by O"Reilly & Associates
Copyright 2003 Danny Goodman
-->
// verify browser language
function getLang(type) {
var lang;
if (typeof navigator.userLanguage != "undefined") {
lang = navigator.userLanguage.toUpperCase();
} else if (typeof navigator.language != "undefined") {
lang = navigator.language.toUpperCase();
}
return (lang && lang.indexOf(type.toUpperCase()) == 0)
}
...
location.href = (getLang("de")) ? "de/home.html" : "en/home.html";
Writing Different Text to a Page Based on the Browser
<script type="text/javascript">
<!--
var browser = navigator.appName;
document.open();
if(browser == "Netscape"){
document.write("<h2>Welcome <a href="http://www.wbex.ru">wbex.ru</a> user.</h2>");
}else if(browser == "Microsoft Internet Explorer"){
document.write("<h2>Welcome <a href="http://www.wbex.ru"> www.wbex.ru</a> user.</h2>");
}else{
document.write("<h2>Welcome. But what browser are you using?</h2>")
}
document.close();
//-->
</script>