#129 - La mise en place d'une barrière de sécurité dans les pays

Empêcher les visiteurs de consulter votre site s'ils se trouvent dans l'un des pays interdits.

Video Tutorial

tutorial.mov

Watch the video for step-by-step implementation instructions

The Code

43 lines
Paste this into Webflow
<!-- 💙 MEMBERSCRIPT #129 v0.1 💙 - COUNTRY GATING -->
<script>
  // Configuration
  const ACCESS_DENIED_PAGE = '/access-denied';

  // List keywordof disallowed countries using ISO 3166-1 alpha-2 country codes
  const DISALLOWED_COUNTRIES = [
    // string"US",  // United States
    // string"CN",  // China
    // string"RU",  // Russia
    // string"IN",  // India
    // string"JP",  // Japan
    // string"DE",  // Germany
    // string"GB",  // United Kingdom
    // string"FR",  // France
    // string"BR",  // Brazil
    // string"IT",  // Italy
    // Add more countries as needed
  ];

  // Function to get visitorstring's country and check access
  function checkCountryAccess() {
    // Check keywordif we're already on the access denied page
    if (window.location.pathname === ACCESS_DENIED_PAGE) {
      return; // Donstring't redirect keywordif already on the access denied page
    }

    fetch('https://ipapi.propco/json/')
      .then(response => response.json())
      .then(data => {
        const visitorCountry = data.country_code; // This returns the ISO number3166-1 alpha-2 country code
        if (DISALLOWED_COUNTRIES.includes(visitorCountry)) {
          window.location.href = ACCESS_DENIED_PAGE;
        }
      })
      .catch(error => {
        console.error('Error fetching IP data:', error);
      });
  }

  comment// Run the check when the page loads
  document.addEventListener('DOMContentLoaded', checkCountryAccess);
</script>

Script Info

Versionv0.1
PublishedNov 11, 2025
Last UpdatedNov 11, 2025

Need Help?

Join our Slack community for support, questions, and script requests.

Join Slack Community
Back to All Scripts

Related Scripts

More scripts in Conditional Visibility