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

164
Vistas
Opening and closing multiple tabs using Javascript on Chrome

I have an anchor tag on my site which on click, should open 4 new tabs using javascript

Anchor Tag: <a onclick="openTabs()"> Open 4 tabsLink </a>

JS Function:

let windows = [];
function openTabs(){
  var locs = [
    'https://www.google.com',
    'https://www.google.com',
    'https://www.google.com',
    'https://www.google.com',
  ]
  for (let i = 0; i < locs.length; i++) {
    windows.push(window.open(locs[i], '_blank'))
  };
}

The user should be able to close all of the 4 tabs by clicking on a single button. The function to close all opened tabs:

function closeTabs(){
      if (windows.length > 0){
        for(var i = 0; i < windows.length; i++){
          windows[i].close();
        }
      }
}

The above code works just fine on Firefox (after I allow pop ups) but on chrome, even the 'openTabs' function doesn't work. It opens only the first link. The closeTabs function throws the below error:

(index):1815 Uncaught TypeError: Cannot read properties of null (reading 'close')

Is there a separate method/API that I should be leveraging to enable this option on chrome? Or is there a more efficient way to do this?

about 4 years ago · Juan Pablo Isaza
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