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

329
Views
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
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!