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

330
Visualizações
How do I close a browser tab after running Python?

I have a web application where I need to open a new tab, run some Python, then close the tab. The reason I'm doing it this way rather than redirecting to the previous page is because the users would like it to retain the search filters.

I'm using Firefox to test it, and I'm aware that Javascript won't close the window if it wasn't opened with Javascript; apparently the same is true if I run any Python functions, because the "cancel" button on the same tab works without any problems.

Things I have tried:

  1. using HttpResponseRedirect to redirect to a new page with a "close" button that runs a Javascript function to close - the function is definitely being called (I can prove this with a window.alert) but the "window.close()" line gets ignored (no errors or anything, it simply does nothing).
  2. using HttpResponse to return 'window.close()' in the Python code - again, if I change it to a window.alert, I can prove the script is running, but again, the 'window.close()' is completely ignored.
  3. adding a window.close() function to the Submit button - this only works if I run it before the "submit", in which case the tab will close, but the "submit" will not happen.

Is there any workaround for this? Making users manually close the new tab with the X button just feels like such an obnoxious way to do it, and this feels like it should be so simple to do.

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