For JavaScript questions, you may find sites such as StackOverflow are a good source of info.
My suspicion is that you can't close a tab unless the javascript opened it, see
https://developer.mozilla.org/en-US/docs/Web/API/Window/close, and so it maybe that your menu written in php has to be responsible for the close.
Reuben