Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to check if a browser is supported

// We want to alert the user if they are using an outdated browser.

// First, we need to check if the browser is supported.
// We can do this by checking the browser's version.
// If the browser's version is less than or equal to 8, we can alert the user.
browserSupport = function() {
    var browser = navigator.appName;
    var version = navigator.appVersion;
    var majorVersion = parseInt(navigator.appVersion, 10);
    var nameOffset, verOffset, ix;
    
    // In Opera, the true version is after "Opera" or after "Version"
    if ((verOffset = version.indexOf("Opera")) != -1) {
        browser = "Opera";
        version = version.substring(verOffset + 6);
    }
    // In MSIE, the true version is after "MSIE" in userAgent
    else if ((verOffset = version.indexOf("MSIE")) != -1) {
        browser = "Microsoft Internet Explorer";
        version = version.substring(verOffset + 5);
    }
    // In Chrome, the true version is after "Chrome"
    else if ((verOffset = version.indexOf("Chrome")) != -1) {
        browser = "Chrome";
        version = version.substring(verOffset + 7);
    }
    // In Safari, the true version is after "Safari" or after "Version"
    else if ((verOffset = version.indexOf("Safari")) != -1) {
        browser = "Safari";
        version = version.substring(verOffset + 7);
    }
    // In Firefox, the true version is after "Firefox"
    else if ((verOffset = version.indexOf("Firefox")) != -1) {
        browser = "Firefox";
        version = version.substring(verOffset + 8);
    }
    // In most other browsers, "name/version" is at the end of userAgent
    else if ((nameOffset = userAgent.lastIndexOf(' ') + 1) < (verOffset = userAgent.lastIndexOf('/'))) {
        browser = userAgent.substring(nameOffset, verOffset);
        version = userAgent.substring(verOffset + 1);
        if (browser.toLowerCase() == browser.toUpperCase()) {
            browser = navigator.appName;
        }
    }
    // trim the version string
    if ((ix = version.indexOf(";")) != -1) version = version.substring(0, ix);
    if ((ix = version.indexOf(" ")) != -1) version = version.substring(0, ix);
    if ((ix = version.indexOf("/")) != -1) version = version.substring(0, ix);
    
    // majorVersion is the major version of the browser
    majorVersion = parseInt('' + version, 10);

    // If the browser is not supported, alert the user.
    if (browser == "Microsoft Internet Explorer" && majorVersion < 8) {
        alert("Your browser is not supported. Please upgrade your browser to continue.");
        return false;
    }
    else if (browser == "Firefox" && majorVersion < 3) {
        alert("Your browser is not supported. Please upgrade your browser to continue.");
        return false;
    }
    else if (browser == "Chrome" && majorVersion < 4) {
        alert("Your browser is not supported. Please upgrade your browser to continue.");
        return false;
    }
    else if (browser == "Safari" && majorVersion < 5) {
        alert("Your browser is not supported. Please upgrade your browser to continue.");
        return false;
    }
    else if (browser == "Opera" && majorVersion < 11) {
        alert("Your browser is not supported. Please upgrade your browser to continue.");
        return false;
    }
    else {
        return true;
    }
}

// If the browser is supported, we can continue.
if (browserSupport()) {
    // We can continue.
}

// Run the function.
browserSupport();

// End of browser support.
Comment

PREVIOUS NEXT
Code Example
Javascript :: WebPack Multiple files 
Javascript :: gojs select node programmatically 
Javascript :: ABORT CONTROLLER WITH ASYNC USEEFFECT REACT 
Javascript :: load jquery in console 
Javascript :: scss in react app 
Javascript :: jsconfig 
Javascript :: JavaScript alert massage prompt 
Javascript :: how to connect socket in react js 
Javascript :: install ejs 
Javascript :: write data in props.histroy.push in react component 
Javascript :: node redirect 
Javascript :: javascript audio navigator audio stream 
Javascript :: api streamelements watchtime 
Javascript :: http status code 406 
Javascript :: delay sleep 
Javascript :: download pdf from drive js 
Javascript :: regex 1-31 days 
Javascript :: set to array casting js 
Javascript :: symbol properties javascript 
Javascript :: how to add multiple style attributes in react element 
Javascript :: nested template strings js 
Javascript :: ask for expo token and save to firebase 
Javascript :: javascript target closest id 
Javascript :: two dimensional array traversing in javascript 
Javascript :: confirm closing tab 
Javascript :: schema mongoose 
Javascript :: remove all chars from string and leave only numbers javascript and leav space betwin numbers 
Javascript :: javascript get first entry from set 
Javascript :: create array in javascript contains 10 elements 
Javascript :: obfuscate js code 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =