1

Until recently this worked in all browsers to close the current window:

window.open('','_self').close();

That no longer seems to be the case in Chrome, Firefox and Edge. I can fix it in Firefox by opening about:config and setting dom.allow_scripts_to_close_windows to true. Does anyone know of a remedy for the others?

  • That code still works in Chrome for me. Have you tried https://developer.mozilla.org/en-US/docs/Web/API/Window/close ? – jmargolisvt Jan 27 '21 at 04:11
  • If my understanding is correct the window will be closed if it was opened with window.open function. Else, it may not. – Arjun Kanungo Jan 27 '21 at 04:19
  • Is there an error in the console? – Barmar Jan 27 '21 at 04:46
  • I just tried doing this by hand in the console in Chrome, and I got the error `Scripts may close only the windows that were opened by them.` – Barmar Jan 27 '21 at 04:46
  • Does this answer your question? [window.close and self.close do not close the window in Chrome](https://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome) – Paul Rooney Jan 27 '21 at 05:02
  • @PaulRooney The answers there say that `close()` can only be called by the same script that called `open()`. That's what this code does. How does that question help? – Barmar Jan 28 '21 at 01:38

0 Answers0