JavaScript Tutorial/Navigator/userAgent

Материал из Web эксперт
Перейти к: навигация, поиск

Get browser type by using the navigator.userAgent

<html>
<head>
<script language="JavaScript" type = "text/javascript">
<!--
var bname = "browser";
if (navigator.userAgent.indexOf("MSIE") != -1)
{
 bname = "Internet Explorer";
}
else if (navigator.userAgent.indexOf("Opera") != -1)
{
 bname = "Opera";
}
else if ((navigator.appName.indexOf("Netscape") != -1) || parseFloat(navigator.appVersion >= 3.0))
{
 bname = "Netscape Navigator";
}
else
{
 bname = "Unknown Browser";
}
document.write("Your browser is: " + bname);
//-->
</script>
<title>Display Browser Information</title>
</head>
<body>
</body>
</html>


navigator.userAgent

<html>
<head>
<title>History</title>
</head>
<body>
<script type="text/javascript">
document.writeln("<h1>navigator object</h1>");
document.writeln("navigator.userAgent: " + navigator.userAgent + "<br />");
document.writeln("navigator.appName: " + navigator.appName + "<br />");
document.writeln("navigator.appCodeName: " + navigator.appCodeName + "<br />");
document.writeln("navigator.appVersion: " + navigator.appVersion + "<br />");
document.writeln("navigator.appMinorVersion: " + navigator.appMinorVersion + "<br />");
document.writeln("navigator.platform: " + navigator.platform + "<br />");
document.writeln("navigator.cookieEnabled: " + navigator.cookieEnabled + "<br />");
document.writeln("navigator.onLine: " + navigator.onLine + "<br />");
document.writeln("navigator.userLanguage: " + navigator.userLanguage + "<br />");
document.writeln("navigator.mimeTypes[1].description: " + navigator.mimeTypes[1].description + "<br />");
document.writeln("navigator.mimeTypes[1].type: " + navigator.mimeTypes[1].type + "<br />");
document.writeln("navigator.plugins[3].description: " + navigator.plugins[3].description + "<br />");
</script>
</body>
</html>