How to Detect User Browser JavaScript Tutorial

Published :
Author :
Adam Khoury

Learn how to detect the user browser software using JavaScript. There are various different ways to go about obtaining the result. This script is written to best convey the logic to someone new to programming. We also make special considerations for modern versions of Internet Explorer browser detection in this exercise.

example.html <script> var ba = ["Chrome","Firefox","Safari","Opera","MSIE","Trident","Edge"]; var b, ua = navigator.userAgent; for(var i=0; i < ba.length; i++){ if( ua.indexOf(ba[i]) > -1 ){ b = ba[i]; break; } } if(b == "MSIE" || b == "Trident" || b == "Edge"){ b = "Internet Explorer"; } alert("You are using " + b + " browser"); </script>