Although most browsers are JavaScript enabled and can understand
all JavaScript code, some browsers or the older versions of certain browsers
cannot understand JavaScript code and ignore it. This leads to unexpected
behavior or undesired results. However, you can handle the situation if
you know the browser and the browser version being used by the visitor.
Once you know the type and the version of the browser
used by the visitors on your website, you can make smart web pages. You
can redirect the users to browser specific pages or display them browser
specific content. To deal with the problem, JavaScript provides Navigator
object that allows you to find out the type of browser its version, and
much more. The following properties of the Navigator object allow you
to get all the information about the browser:
·
appName: This property gives the name of the browser used.
·
appVersion: This property gives the version information of the browser
used.
·
appCodeName: This property gives the code name of the browser used. The
code name of both Internet Explorer and Netscape Navigator is “Mozilla”.
·
platform: This property gives the information about the platform on which
browser is running, such as Windows or Macintosh.
·
cookieEnabled: This property gives the information about the cookies.
It tells whether the cookies are enabled on the browser or not.
·
language: This property gives the language version of the browser. For
example ‘en’ would be returned for the English language.
·
userAgent: This property gives the information about the appName and appVersion
of the browser if the browser does not identify itself with appName and
appVersion properties.
<html>
<head>
<script type="text/javascript">
document.write("Browser Name: " + navigator.appName);
document.write("<br /><br />");
document.write("Browser Version: " + navigator.appVersion);
document.write("<br /><br />");
document.write("Browser CodeName: " + navigator.appCodeName);
document.write("<br /><br />");
document.write("Cookies Enabled: " + navigator.cookieEnabled);
document.write("<br /><br />");
document.write("Platform: " + navigator.platform);
document.write("<br /><br />");
document.write("User-agent header: " + navigator.userAgent);
</script>
</body>
</html> |
Result of the code
|