Browser Detective : Browser Detect « Development « JavaScript Tutorial






<html>
<head>
<title>Browser Detective</title>
<script>
var bVersion = 0;
var isNav = false;
var isIE = false;

function checkBrowser(){
  if (navigator.appName == "Netscape"){
    isNav = true;
  } else {
    if (navigator.appName == "Microsoft Internet Explorer"){
      isIE = true;
    }
  }

  bVersion = parseInt(navigator.appVersion);

  if (bVersion < 4){
    alert("Consider getting a newer browser! This code might not work!");
  }

  if ((!isNav) && (!isIE)){
    alert("I do not recognize this browser. This code might not work");
  }
}

</script>
</head>

<body>
<center>
<h1>Browser Detective<hr></h1>
<script>
checkBrowser();

if (isNav){
  document.write("Netscape Navigator");
} else {
  if (isIE){
    document.write("Internet Explorer");
  }
}

</script>
</center>
</body>
</html>








4.2.Browser Detect
4.2.1.Browser Detective