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

159
Vistas
When Tab is clicked replace window

im trying to do an Language Switcher for a Website and i am using an Tab element with 2 Tabs -

Now i am trying to do a window.location.replace to an url when one of the tabs is clicked.

So tab 1 should link to google.de and tab 2 to google.com

I dont quite know how to define each tab

thats the current code i got

<script>
// when DOM ready
$(document).ready(function() {
  // if 'tab' item exists in localStorage
  if(localStorage.getItem('tab')){
    // click the respective tab button
    // e.g. if 'tab' item value == 0
    // click tab[0]
    $('.tab-button')[localStorage.getItem('tab')].click();
  }
});

// on tab click
$('.tab-button').click(function(){
  // get its index
  const index = $('.tab-button').index(this);
  // store the index in localStorage
  localStorage.setItem('tab',index);
});
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

<script>
// when DOM ready
$(document).ready(function() {
  // if 'tab' item exists in localStorage
  if(localStorage.getItem('tab')){
    // click the respective tab button
    // e.g. if 'tab' item value == 0
    // click tab[0]
    $('.tab-button')[localStorage.getItem('tab')].click();
  }
});

// on tab click
$('.tab-button').click(function(){
  // get its index
  const index = $('.tab-button').index(this);
  // store the index in localStorage
  localStorage.setItem('tab',index);

  if (index == 1) {window.open('google.de', '_self');} 
  else if (index == 2) {window.open('google.com', '_self');}
  else {//open default window}

});
</script>
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