• 24-03-2022, 13:47:08
    #1
    <script type='text/javascript'>
    fetch('https://api.country.is/')
      .then(function(response) {
        return response.json();
      })
      .then(function(data) {
       if(data.country == 'TR') {
           window.location.replace("http://tr.com");
       }
      });
    </script>
    Merhaba, elimde böyle bir kod var. API üzerinden hangi ülkede olduğumuzu ve ülke kodunu alıp ona göre yönlendirme yapıyoruz. Fakat bana bunun biraz daha farklısı lazım ve uğraştım yapamadım.

    Eğer ziyaretçi TR'de ise TR sayfasına
    US ise US sayfasına
    UK ise UK sayfasına
    CA ise CA sayfasına gibi gibi
    EĞER hiçbiri değilse standart anasayfaya yönlensin gibi bir şey yazmak istiyorum ama çalıştıramadım. Anlayan yardımcı olacak var mı?
  • 24-03-2022, 13:53:26
    #2
    Sorun çözülürse bilgi verin lütfen Takip
  • 24-03-2022, 13:57:38
    #3
    fetch('https://api.country.is/')
      .then(function(response) {
        return response.json();
      })
      .then(function(data) {
       if(data.country == 'TR') {
           window.location.replace("trlink");
       }else if(data.country == 'US') {
           window.location.replace("uslink");
       }else if(data.country == 'UK') {
           window.location.replace("uklink");
       }else if(data.country == 'CA') {
           window.location.replace("calink");
       }else{
            window.location.replace("defaultlink");
       }
      });
  • 24-03-2022, 14:00:16
    #4
    dev
    Kurumsal Üye
    fetch('https://api.country.is/')
        .then(function(response) {
            return response.json();
        })
        .then(function(data) {
            switch (data.country) {
                case 'TR':
                    window.location.replace("http://tr.com");
                    break;
                case 'US':
                    window.location.replace("http://en.com");
                    break;
                default:
                    window.location.replace("http://standart.com");
    
            }
        });
  • 24-03-2022, 14:19:37
    #5
    TuorElanesse adlı üyeden alıntı: mesajı görüntüle
    fetch('https://api.country.is/')
      .then(function(response) {
        return response.json();
      })
      .then(function(data) {
       if(data.country == 'TR') {
           window.location.replace("trlink");
       }else if(data.country == 'US') {
           window.location.replace("uslink");
       }else if(data.country == 'UK') {
           window.location.replace("uklink");
       }else if(data.country == 'CA') {
           window.location.replace("calink");
       }else{
            window.location.replace("defaultlink");
       }
      });
    Noroc adlı üyeden alıntı: mesajı görüntüle
    fetch('https://api.country.is/')
        .then(function(response) {
            return response.json();
        })
        .then(function(data) {
            switch (data.country) {
                case 'TR':
                    window.location.replace("http://tr.com");
                    break;
                case 'US':
                    window.location.replace("http://en.com");
                    break;
                default:
                    window.location.replace("http://standart.com");
    
            }
        });
    İkisini de deneyeceğim muhtemelen çalışıyordur teşekkürler
  • 24-03-2022, 14:21:20
    #6
    İkisi de çalışıyor elinize sağlık