How to Detect Visitor's Browser Using JavaScript?


How to Detect Visitor's Browser Using JavascriptYou can detect which and what version of browser have used by your website visitors by using simple JavaScript codes. The navigator object in JavaScript contains information about the visitor's browser. It includes information about the visitor's browser name, browser version and more. It can be very useful to detect the visitor's browser type and version, and then serve up the appropriate information. By using this feature in JavaScript, it is easier to make your web pages smart enough to look one way to some browsers and another way to other browsers. But it may not be work for some browsers, specially for older browsers, which do not support JavaScript.

Here are some steps and codes for detecting visitor's browser using JavaScript, it may help you to apply this feature in your website.



Code for Detecting Visitor's Browser and Browser Version Using JavaScript


<script type="text/javascript">
var x=navigator

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("BrowserLanguage=" + x.browserLanguage)
document.write("<br/>")
document.write("SystemLanguage=" + x.systemLanguage)
document.write("<br/>")
document.write("UserLanguage=" + x.userLanguage)
</script>

Where: 

  • appName - It holds the application name of the browser.
  • appVersion - It holds the version of the application and other things.
  • cookieEnabled - It checks whether or not cookie is enabled.
  • browserLanguage - It holds the browser Language.
  • systemLanguage - It holds the system Language.
  • userLanguage - It holds the user Language.



Output of the Code for Detecting Visitor's Browser and Browser Version 





Example: Alert user for older browser



You can alert or inform the visitor of  your website by using navigator object in JavaScript as the following. Here in the given code, the browsers below the version 4 are treated as older browser and displays the message. You can also add the links to download the latest version of browsers. 

<script type="text/javascript">

var browser= x.appName
var version = parseFloat(x.appVersion)

if((browser="Netscape" || browser=="Microsoft Internet Explorer") && (version>=4))

{document.write("Your browser is good enough!")
document.write("<br/>")}

else
{document.write("Your browser is old Update browser!")
document.write("<br/>")}

</script>

Output of the above Code  





Related Posts

شاب أردني عمري 16 سنة أحب كل جديد في عالم الانترنت من مواقع وبرامج واحب التدوين ودائما ابحث عن الجديد لتطوير مهاراتي في مختلف الميادين التي تعجبني لكي انقل لكم وانا مدون واعمل فى مجال التدوين منذ فترة واحب معرفة الجديد والتعرف على الصدقاء .

شارك المقالة

مقالات ذات صلة