Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

browser support

// 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 :: js min number in array 
Javascript :: how to add background to kaboom js 
Javascript :: Javascript code to Detect All Network Number In Nigeria (MTN, Glo, Airtel & 9Mobile). 
Javascript :: hash url owl carousel example 
Javascript :: expo av 
Javascript :: remove cookie 
Javascript :: display object in array 
Javascript :: javascript get all elements of an id 
Javascript :: ejs docs 
Javascript :: validation for start date and end date in jquery 
Javascript :: JavaScript max 32-bit integer 
Javascript :: only allow requests from domain express 
Javascript :: jquery generate post entire page 
Javascript :: javascript round down to 2 decimal places 
Javascript :: react import coreui icons 
Javascript :: js email validation 
Javascript :: js set value in object only if defined 
Javascript :: how to give default value in jquery 
Javascript :: merge two binary trees 
Javascript :: private methods js 
Javascript :: react native stack transition from right to left 
Javascript :: how to log bodyparser error 
Javascript :: javascript target closest 
Javascript :: how to filter an array of strings to see which letters match javascript 
Javascript :: inertia-link vuetify 
Javascript :: JavaScript - Closures 
Javascript :: get all data in collection firebase react 
Javascript :: svg event listeners 
Javascript :: react native updating options with setoptions 
Javascript :: practice javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =