Closing a Window in JavaScript

If you’re having trouble closing a window using JavaScript, this might help. I’ve had this problem sometimes in Chrome in particular when I open a window, then follow through a bunch of redirects or something. It seems to lose track of the fact that I “control” this window object, so it doesn’t allow me to close it. This fixes that:

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

Basically it reopens the window on itself, then immediately closes itself. Neat. Haven’t had any problems with it not working in other browsers, but I also haven’t super-widely tested it.

    • Beau Lebens said:

      No, this needs to be part of a function/method/script that is tryingto close a window that's previously been opened programmatically.

Comments are closed.