Using JS to Close a Window You Didn’t Open

We all know it’s impossible to use JavaScript to close arbitrary windows, right? One of the first things you learn when playing with opening and closing windows with JavaScript is that, for security reasons, you can’t close a window that you didn’t open.

Well, as it turns out, you can, as I recently learned from this post on ASP Alliance. I won’t reveal the secret here, but if you want proof that it works, here it is:

This is a traditional attempt to close the main browser window. It shouldn’t work in most browsers — at least not without prompting. This, on the other hand, is an attempt that should work. Goodbye.