Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!