How to show an outdated browser alert on Internet Explorer 11

Follow me!

If you like this article, go ahead and follow me on Twitter:

Follow @getButterfly

Here’s a nice overview on why Internet Explorer 11 should be phased out and users blocked from viewing the site content when using the aforementioned browser.

Next, as the title says, here’s how to detect an IE 11 browser:

// Method #1: Detect IE 10 and IE 11
function isIE() {
    // IE 10 and IE 11
    return /Trident\/|MSIE/.test(window.navigator.userAgent);

Or IE 11-only:

let isIE11 = (function () {
    // true on IE11, false on Edge and other IEs/browsers.
    let isIE11 = !!window.MSInputMethodContext && !!document.documentMode,
        ua = window.navigator.userAgent;

    if (ua.indexOf("AppleWebKit") > 0) {
        return false;
    } else if (ua.indexOf("Lunascape") > 0) {
        return false;
    } else if (ua.indexOf("Sleipnir") > 0) {
        return false;

    array = /(msie|rv:?)\s?([\d\.]+)/.exec(ua);
    version = (array) ? array[2] : '';

    return (version === 11) ? true : false;

Next, we need to display an outdated/unsupported browser alert:

let showBrowserAlert = (function () {
    if (document.querySelector('.unsupported-browser')) {
        let d = document.getElementsByClassName('unsupported-browser');

        is_IE11 = isIE11();

        if (is_IE11) {
            d[0].innerHTML = '<b>Unsupported Browser!</b> This website will offer limited functionality in this browser. We only support the recent versions of major browsers like Chrome, Firefox, Safari, and Edge.';
            d[0].style.display = 'block';

document.addEventListener('DOMContentLoaded', showBrowserAlert);

Don’t forget to add an empty <div class="unsupported-browser"></div> right after the opening <body>.

Find more JavaScript tutorials, code snippets and samples here or more jQuery tutorials, code snippets and samples here.

πŸ‘‹ Added by Ciprian on Thursday, August 22, 2019 in JavaScript. Last modified on Thursday, August 22, 2019.


Contribute to this article by sharing your opinion on Twitter:

Unlimited Automated Page Speed Monitoring & Tracking.
Use SpeedFactor to track your website. It’s simple and reliable.
See how real people experience the speed of your website. Then find (and fix) your web performance problems.
Get Started
Privacy Policy