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

221
Vistas
Detect multiple tabs opening... and close the newest tabs! (via BroadcastChannel API)

I've put this function on load so I can detect a new tab being opened:

function checkNewTabs() {
  const channel = new BroadcastChannel('tab');
  channel.postMessage('newTab');
  channel.addEventListener('message', (msg) => {
    if (msg.data === 'newTab') {
      alert('Please don't open more than one tab at a time!');
      //window.open('', '_self', '').close();
    }
  });
}

I want to be able to send a message back to the new tab like this:

channel.postMessage('callbackNewTab');
channel.addEventListener('message', (msgBack) => {
  if (msgBack.data === 'callbackNewTab') {
    alert('This tab will be closed!');
    window.open('', '_self', '').close();
  }
});

In order to close the new tab...

I can do it for the old tab but what I really need is for it to close the new tab!

Can anyone help me out please? tks! :)

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