How to detect my running Browser using Javascript?

Using following Javascript code, we can detect the Browsers & Browsers Version, like either running the current url is Google Chrome or Firefox or Internet Explorer or Safari.

using this way we can provide the alert to users to upgrade the old versions of browsers.


Browser Details

<script type="text/javascript">// < !&#91;CDATA&#91;
// < !&#91;CDATA&#91;
//get the launched browser details
function getLaunchBrowser() {
    var userAgent = navigator.userAgent.toLowerCase();
    //alert('userAgent'+userAgent);
    var currentBrowser = '';
	var browserCompat = 'true';
    var currentBrowserVersion = 0;
    var version = 0;
    if (userAgent.match('msie')) {
        currentBrowser = 'IE';
    }
    else if (userAgent.match('trident')) {
        currentBrowser = 'IE11';
    }
    else if (userAgent.match('chrome')) {
        currentBrowser = 'Chrome';
    }
    else if (userAgent.match('firefox')) {
        currentBrowser = 'Firefox';
    }
    else {
        currentBrowser = 'Not Supported';
    }
	//alert('currentBrowser'+currentBrowser);
    switch (currentBrowser) {
        case 'IE11':
            version = 11;
            browserCompat = "false";
            break;
        case 'IE9':
            version = 9;
			//alert('version'+version);
            browserCompat = "false";
            break;
        case 'IE':
            currentBrowserVersion = userAgent.substring(userAgent.indexOf('msie ') + 5);
            //alert('currentBrowserVersion'+currentBrowserVersion);
            version = currentBrowserVersion.split('.');
            version = version&#91;0&#93;;
			//alert('version'+version);
            if (version <= 6) {
                browserCompat = "false";
            }
            else {
            }
            break;
        case 'Chrome':
            currentBrowserVersion = userAgent.substring(userAgent.indexOf('chrome/') + 7);
            version = currentBrowserVersion.split('.');
            version = version&#91;0&#93;;
			//alert('version'+version);
            if (version <= 30) {
                browserCompat = "false";
            }
            else {
            }
            break;
        case 'Firefox':
            currentBrowserVersion = userAgent.substring(userAgent.indexOf('firefox/') + 8);
            version = currentBrowserVersion.split('.');
            version = version&#91;0&#93;;
			//alert('version'+version);
            if (version <= 25) {
                browserCompat = "false";
            }
            else {
            }
            break;
        case 'Not Supported':
            browserCompat = "false";
        default:
            break;
    }

	alert('browserCompat:::'+browserCompat);
}
// &#93;&#93;></script>

(781)

Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in IBM Austraila as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 9 Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply