Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1K
Visualizações
How to switch to a specific browser tab programmatically using JavaScript with same origin?

I'm using google chrome browser and trying to switch the focus between two browser tabs whose origin is same using JavaScript.

I open a tab say tab_1 using

window.open("www.example.com/{data}","_blank");

And then I open some new tabs say tab_2, tab_3 and tab_4 in the same browser and go back to the first tab tab_1 (www.example.com/{data}). Then I do some work on tab_4 and after clicking on the submit button, I close the current tab using window.close() and the focus goes to tab_3 but I want to shift the focus to tab_1 instead.

So, how can I change the focus of the current browser to a specific tab which I opened using window.open() statement?

If it's not possible using Javascript, please help me with any other solution to achieve this.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In the window that you open with window.open() you have the window.opener option, that is the instance that open that tab. But you can't switch between tabs with JavaScript. Wat you can do, after window.close(), is reload the current tab to the destination you want.

about 4 years ago · Juan Pablo Isaza Relatório

0

If you use in a button

<button onclick="window.close();">Close</button>

if you use in function

function closeWin() {
  myWindow.close(); 
}

But it will only work when you open a window through your code like this

function openWin() {
  myWindow = window.open("", "myWindow", "width=200, height=100");
}

You can't close the current window that was open by browser. beacuse browser don't give permission.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda