How to use Javascript detect browser type

The window.navigator object contains information about the visitor’s browser and the Navigator interface represents the state and the identity of the user agent. We can use a navigator to query it and to register themselves to carry on some activities.

Example of Javascript detect browser

Let create an HTML file to demonstrate how we can use detect browser type using Javascript code.

Javascript detect browser
Javascript detect browser type
<!DOCTYPE html>

        function detectBrowser() {
            if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
            } else if (navigator.userAgent.toLowerCase().indexOf('edg') > -1) {
            } else if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
            } else if (navigator.userAgent.toLowerCase().indexOf('safari') > -1) {
            } else if ((navigator.userAgent.indexOf('opera') || navigator.userAgent.indexOf('OPR')) != -1) {
            } else if (navigator.userAgent.indexOf("MSIE") != -1) {
            } else {


    <h2>Javascript Detect mobile and desktop device</h2>

    <button type="button" onclick="detectBrowser()">Detect Browser</button>


Javascript code to determine chrome version

function getChromeVersion () {     
    var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
    return raw ? parseInt(raw[2], 10) : false;
alert(getChromeVersion ());

Related posts

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top