0

Steps to reproduce:

  1. Open wikipidia.org in a chrome tab and open the devtools.
  2. Enter the following command

p = window.open('https://www.google.com')

Once the window opens, entering p.closed returns true.

But, If we replace the url of target window from https://www.google.com to https://www.yahoo.com, p.closed returns false

Am I missing something?

Faihan
  • 113
  • 1
  • 9
  • 1
    `window.closed` always returns `true` if the opener is not on the same domain as the opener, and if certain headers have not been set in the response. yahoo.com has set those headers. I can't remember exactly what headers/CORS is required, but you should be able to research those if necessary. The main point is that you (as the client opening third party sites) cannot rely on `window.closed` being accurate when working with third-party/cross-domain sites. – Rory McCrossan Jul 16 '23 at 13:41
  • Thank you. Adding Access-Control-Allow-Origin header to the response works. Would you allow me to post your comment as an answer and mark it as accepted? – Faihan Jul 16 '23 at 13:56
  • No problem, glad to help. I closed it as a duplicate. – Rory McCrossan Jul 16 '23 at 13:58

0 Answers0