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

159
Views
how would I catch a JavaScript warning in a try / catch statement?

I need to be able to check if I can close the current page, however since it returns the warning "Scripts may close only the windows that were opened by them." It wont be caught by a try/catch statement because it isn't an "error". Is there any way I can get around this?

function attemptToClose() {
  try {
     window.close();
  }
  catch(err) {
    //do something different
    console.log(err)
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understand this correctly window.close(); can only close pages open by itself aka window.open();. This might be a security prevention method so that websites do not take control of your browsers.

Try initiating the page with window.open(); then try using the window.close();.

Hope this solves it!

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