âš ī¸ Warning âš ī¸ Deprecated Code! This video tutorial contains outdated code.
💡 If you wish to update it, any AI assistant will update the code for you in seconds.

How to Detect User Browser JavaScript Tutorial

Published : April 19, 2016   •   Last Edited : November 24, 2025   •   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) > -1 ){
        b = ba;
        break;
    }
}
if(b == "MSIE" || b == "Trident" || b == "Edge"){
    b = "Internet Explorer";
}
alert("You are using " + b + " browser");
</script>