Please see my comment to the question. First of all, I would strongly advise to review your UI design and avoid such things. The problem is not even closing. More basic problem is
window.open
. This is called "popup" and has
very bad reputation. Not only it is too intrusive to be convenient enough for the users, but many user fight against popups with popup blocking software, most typically in the form of browser plug-ins. Your whole window may not show up at all.
After this warning, I'll give you the formal answer, but it won't work in a number of cases. Here is the recipe:
var popup = window.open(
popup.close();
Also,
window.close()
closes current window:
https://developer.mozilla.org/en-US/docs/Web/API/Window/close[
^].
But the current-window approach may not work in some cases. Say, it won't work if your window is actually a tab. JavaScript cannot "see" the difference, but it won't just work. First approach based on the return from
open
should work.
I already suggested: don't do it. One reasonable alternative would be so called
modal popup (this name is doubly confusing; in fact, this is some emulation of modal-like behavior on the same page; but it
solves nearly all problems). For further detail, please read my last article, where I explain it all in detail, and, but they way, provide yet another implementation:
Modal Popup From Scratch[
^].
But you don't have to use my implementation: there is jQuery Dialog Widget and many (really many) 3rd-party plug-ins and other implementations.
—SA