Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
My redirect isn't working well with IPInfo.io

I need help with redirect to subdomains. With IPinfo I get country of visitor then i redirect him to one of my subdomains and i need this look like ua.mysite or kz.mysite or ru.mysite I tried window.location.href = data.country + 'mysite' but this didn't work. Hope you can help me! :)

  // Let's check if we have the value in localstorage
  if (localStorage.getItem('country') == 'RU') {
    // Already have the value in localStorage no need to make call to IPinfo
     window.location.hostname = 'ru.mysite.tech'
  } else if(localStorage.getItem('country') == 'KZ') {
    // Already have the value in localStorage no need to make call to IPinfo
     window.location.hostname = 'kz.mysite.tech'
  } else if(localStorage.getItem('country') == 'UA') {
    // Already have the value in localStorage no need to make call to IPinfo
     window.location.hostname = 'ua.mysite.tech'
  }

  else{
    // No cached data, let's get it from IPinfo
    fetch('https://ipinfo.io/json?<MyToken>')
      .then(res => res.json())
      .then(data => {
        if(data.country == 'UA'){
          localStorage.setItem('ipinfo', data.country)
          window.location.hostname = 'ua.mysite.tech'
        }
        else if(data.country == 'KZ'){
          localStorage.setItem('ipinfo', data.country)
          window.location.hostname = 'kz.mysite.tech'
        }
        else {
          localStorage.setItem('ipinfo', data.country)
          window.location.hostname = 'ru.mysite.tech'
        }
    })
  }
}```
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Updates to window.location.hostname don't cause redirect.

You should update window.location directly like this (note the "https:/"):

if (localStorage.getItem('country') == 'RU') {
  // Already have the value in localStorage no need to make call to IPinfo
   window.location = 'https://ru.mysite.tech'
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda