WebDevelopersNotes logo

home-icon Home / JavaScript / Browser detection through JavaScript – Navigator Object

Browser detection through JavaScript – Navigator Object

Browser detection through JavaScript – Navigator Object

Getting client (browser) details is very easy through JavaScript. Client name, version, codename and the platform used are available through the navigator object and its properties. (The navigator object was named after Netscape Navigator).

  • navigator.appName – Gives the name of the browser (application Name)
  • navigator.appVersion – Gives the browser version (application Version)
  • navigator.appCodeName – Gives the browser codename (application CodeName)
  • navigator.platform – Gives the platform on which the browser is running

Because of browser incompatibility issue in DHTML, some web developers make two versions of their site, one that is compatible with Internet Explorer and the other that contains Netscape Navigator specific code. These developers use a browser detection script to transfer the visitor to the respective site.

We’ll concentrate only on Internet Explorer and Netscape Navigator since they are the most prominent browsers on the Internet.

To automatically transfer the visitor, we have to take the help of location property of the window object. Let’s look at the code.

<SCRIPT LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">
<!--

var bname = navigator.appName;
if (bname == "Microsoft Internet Explorer")
   {
   window.location="explorer_version.html";
   }
else
   {
   window.location="netscape_version.html";
   }

//-->
</SCRIPT>

Deconstruction of the browser detection script

The browser name is obtained through navigator.appName and is stored in variable bname. Using an if statement we check the value of this variable. If it’s “Microsoft Internet Explorer”, we transfer the visitor to explorer_version.html else, the visitor is taken to netscape_version.html. Note that window.location takes a URL as value.

Sponsored Links

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Sponsored Links

Tips

How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]

Fact

Credit for creating the modern computer mouse with an optical encoder, single ball and two buttons goes to Jean-Daniel Nicoud of the Ecole Polytechnique Federale de Lausanne in Switzerland. This was a major improvement over original computer mouse created by Douglas Engelbart. Jean-Daniel Nicoud was assisted by André Guignard during the design process. The "Guignard mouse" was ready in 1977 and picked up by Logitech who saw the potential in the device. In 1980s, they started to get the computer peripheral manufactured from another Swiss company, Dubois Depraz SA. With the proliferation of GUI-based operating systems, the mouse soon became extremely popular. By the end of 2008, Logitech announced that they had sold 1 billion of these. [more...]

We use cookies to give you the best possible website experience. By using WebDevelopersNotes.com, you agree to our Privacy Policy