#191 - Browser Compatibility Notice v0.1

Automatically detect outdated browsers and display a dismissible notice.

View demo


<!-- 💙 MEMBERSCRIPT #191 v0.1 💙 - BETTER BROWSER COMPATIBILITY NOTICES -->

<script>

(function() {

  'use strict';

  // ═══════════════════════════════════════════════════════════════

  // CONFIGURATION

  // ═══════════════════════════════════════════════════════════════

  const CONFIG = {
    // Minimum supported browser versions
    MIN_VERSIONS: {
      chrome: 90,
      firefox: 88,
      safari: 14,
      edge: 90,
      opera: 76
    },
    // Messages for different browser types
    MESSAGES: {
      outdated: 'Your browser is outdated and may not support all features. Please update for the best experience.',
      unsupported: 'Your browser is not fully supported. Please use a modern browser like Chrome, Firefox, Safari, or Edge.',
      update: 'Update your browser',
      dismiss: 'Dismiss'
    },
    // Show notice even if dismissed (for testing)
    // Set to true to always show the notice, regardless of browser or dismissal state
    FORCE_SHOW: false,
    // Storage key for dismissed state
    STORAGE_KEY: 'ms_browser_notice_dismissed'
  };

  

  // ═══════════════════════════════════════════════════════════════

  // BROWSER DETECTION

  // ═══════════════════════════════════════════════════════════════

  function getBrowserInfo() {
    const ua = navigator.userAgent;
    let browser = { name: 'unknown', version: 0 };

    

    // Internet Explorer (all versions unsupported)
    if (/MSIE|Trident/.test(ua)) {
      return { name: 'ie', version: 0, unsupported: true };
    }

    

    // Chrome
    const chromeMatch = ua.match(/Chrome\/(\d+)/);
    if (chromeMatch && !/Edg|OPR/.test(ua)) {
      return { name: 'chrome', version: parseInt(chromeMatch[1], 10) };
    }

    

    // Edge (Chromium-based)
    const edgeMatch = ua.match(/Edg\/(\d+)/);
    if (edgeMatch) {
      return { name: 'edge', version: parseInt(edgeMatch[1], 10) };
    }

    

    // Legacy Edge (unsupported)
    if (/Edge\/\d/.test(ua) && !/Edg/.test(ua)) {
      return { name: 'edge-legacy', version: 0, unsupported: true };
    }

    

    // Firefox
    const firefoxMatch = ua.match(/Firefox\/(\d+)/);
    if (firefoxMatch) {
      return { name: 'firefox', version: parseInt(firefoxMatch[1], 10) };
    }

    

    // Safari (must check for Chrome first to avoid false positives)
    const safariMatch = ua.match(/Version\/(\d+).*Safari/);
    if (safariMatch && !/Chrome|Chromium/.test(ua)) {
      return { name: 'safari', version: parseInt(safariMatch[1], 10) };
    }

    

    // Opera
    const operaMatch = ua.match(/OPR\/(\d+)/);
    if (operaMatch) {
      return { name: 'opera', version: parseInt(operaMatch[1], 10) };
    }

    

    return browser;
  }

  

  function isBrowserOutdated(browser) {
    // Unsupported browsers (IE, legacy Edge)
    if (browser.unsupported) {
      return { outdated: true, reason: 'unsupported' };
    }

    

    // Unknown browser
    if (browser.name === 'unknown') {
      return { outdated: false, reason: 'unknown' };
    }

    

    // Check against minimum versions
    const minVersion = CONFIG.MIN_VERSIONS[browser.name];
    if (minVersion && browser.version < minVersion) {
      return { outdated: true, reason: 'outdated', current: browser.version, required: minVersion };
    }

    

    return { outdated: false, reason: 'supported' };
  }

  

  // ═══════════════════════════════════════════════════════════════

  // STORAGE HELPERS

  // ═══════════════════════════════════════════════════════════════

  function isDismissed() {
    if (CONFIG.FORCE_SHOW) return false;
    try {
      return localStorage.getItem(CONFIG.STORAGE_KEY) === 'true';
    } catch (e) {
      return false;
    }
  }

  

  function setDismissed() {
    try {
      localStorage.setItem(CONFIG.STORAGE_KEY, 'true');
    } catch (e) {
      // Silently fail if localStorage is not available
    }
  }

  

  // ═══════════════════════════════════════════════════════════════

  // NOTICE DISPLAY

  // ═══════════════════════════════════════════════════════════════

  function getBrowserUpdateUrl(browserName) {
    const urls = {
      chrome: 'https://www.google.com/chrome/',
      firefox: 'https://www.mozilla.org/firefox/',
      safari: 'https://www.apple.com/safari/',
      edge: 'https://www.microsoft.com/edge',
      opera: 'https://www.opera.com/download',
      'edge-legacy': 'https://www.microsoft.com/edge',
      ie: 'https://www.microsoft.com/edge'
    };
    return urls[browserName] || 'https://browsehappy.com/';
  }

  

  function createNotice(browser, status) {
    // Only works with custom Webflow-designed container
    const customContainer = document.querySelector('[data-ms-code="browser-notice"]');
    if (!customContainer) {
      return;
    }

    

    // Show the container (override CSS display:none if set in Webflow)
    const computedStyle = window.getComputedStyle(customContainer);
    if (computedStyle.display === 'none' || customContainer.style.display === 'none') {
      // Set explicit display value to override CSS rule
      // Use 'block' as default, or preserve original if it was set via inline style
      customContainer.style.setProperty('display', 'block', 'important');
    }

    

    // Populate individual elements within the container
    const messageEl = customContainer.querySelector('[data-ms-code="browser-notice-message"]');
    const updateLinkEl = customContainer.querySelector('[data-ms-code="browser-notice-update"]');
    const dismissBtnEl = customContainer.querySelector('[data-ms-code="browser-notice-dismiss"]');

    

    // Populate message
    if (messageEl) {
      const isUnsupported = status.reason === 'unsupported';
      messageEl.textContent = isUnsupported ? CONFIG.MESSAGES.unsupported : CONFIG.MESSAGES.outdated;
    }

    

    // Populate update link
    if (updateLinkEl) {
      const updateUrl = getBrowserUpdateUrl(browser.name);
      // Handle both <a> tags and other elements
      if (updateLinkEl.tagName.toLowerCase() === 'a') {
        updateLinkEl.href = updateUrl;
        updateLinkEl.setAttribute('target', '_blank');
        updateLinkEl.setAttribute('rel', 'noopener noreferrer');
      } else {
        // For buttons or other elements, add onclick
        updateLinkEl.onclick = function(e) {
          e.preventDefault();
          window.open(updateUrl, '_blank', 'noopener,noreferrer');
        };
      }
      updateLinkEl.textContent = CONFIG.MESSAGES.update;
    }

    

    // Populate dismiss button
    if (dismissBtnEl) {
      dismissBtnEl.textContent = CONFIG.MESSAGES.dismiss;
      attachDismissHandler(customContainer);
    }

    

    return customContainer;
  }

  

  function attachDismissHandler(container) {
    const dismissBtn = container.querySelector('[data-ms-code="browser-notice-dismiss"]');
    if (dismissBtn) {
      dismissBtn.addEventListener('click', function() {
        setDismissed();
        // Hide container using Webflow's own styling
        container.style.display = 'none';
      });
    }
  }

  

  // ═══════════════════════════════════════════════════════════════

  // INITIALIZATION

  // ═══════════════════════════════════════════════════════════════

  function init() {
    // Check if custom container exists (designed in Webflow)
    const customContainer = document.querySelector('[data-ms-code="browser-notice"]');
    if (!customContainer) {
      return;
    }

    

    // Hide banner if already dismissed (unless force show)
    if (isDismissed() && !CONFIG.FORCE_SHOW) {
      customContainer.style.display = 'none';
      return;
    }

    

    // Wait for DOM to be ready
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', checkAndShowNotice);
    } else {
      checkAndShowNotice();
    }
  }

  

  function checkAndShowNotice() {
    const browser = getBrowserInfo();
    const status = isBrowserOutdated(browser);

    

    const customContainer = document.querySelector('[data-ms-code="browser-notice"]');

    

    if (status.outdated || CONFIG.FORCE_SHOW) {
      createNotice(browser, status);
    } else {
      // Hide banner if browser is up to date
      if (customContainer) {
        customContainer.style.display = 'none';
      }
    }
  }

  

  // Start initialization
  init();
})();

</script>

Customer Showcase

Have you used a Memberscript in your project? We’d love to highlight your work and share it with the community!

Creating the Make.com Scenario

1. Download the JSON blueprint below to get stated.

2. Navigate to Make.com and Create a New Scenario...

3. Click the small box with 3 dots and then Import Blueprint...

4. Upload your file and voila! You're ready to link your own accounts.

Need help with this MemberScript?

All Memberstack customers can ask for assistance in the 2.0 Slack. Please note that these are not official features and support cannot be guaranteed.

Join the 2.0 Slack
Version notes
Attributes
Description
Attribute
No items found.
Guides / Tutorials
No items found.
Tutorial
What is Memberstack?

Auth & payments for Webflow sites

Add logins, subscriptions, gated content, and more to your Webflow site - easy, and fully customizable.

Learn more

"We've been using Memberstack for a long time, and it has helped us achieve things we would have never thought possible using Webflow. It's allowed us to build platforms with great depth and functionality and the team behind it has always been super helpful and receptive to feedback"

Jamie Debnam
39 Digital

"Been building a membership site with Memberstack and Jetboost for a client. Feels like magic building with these tools. As someone who’s worked in an agency where some of these apps were coded from scratch, I finally get the hype now. This is a lot faster and a lot cheaper."

Félix Meens
Webflix Studio

"One of the best products to start a membership site - I like the ease of use of Memberstack. I was able to my membership site up and running within a day. Doesn't get easier than that. Also provides the functionality I need to make the user experience more custom."

Eric McQuesten
Health Tech Nerds
Off World Depot

"My business wouldn't be what it is without Memberstack. If you think $30/month is expensive, try hiring a developer to integrate custom recommendations into your site for that price. Incredibly flexible set of tools for those willing to put in some minimal efforts to watch their well put together documentation."

Riley Brown
Off World Depot

"The Slack community is one of the most active I've seen and fellow customers are willing to jump in to answer questions and offer solutions. I've done in-depth evaluations of alternative tools and we always come back to Memberstack - save yourself the time and give it a shot."

Abbey Burtis
Health Tech Nerds
Slack

Need help with this MemberScript? Join our Slack community!

Join the Memberstack community Slack and ask away! Expect a prompt reply from a team member, a Memberstack expert, or a fellow community member.

Join our Slack