The event of pressing a button on the code code only processes the code that affects the server. Closing the browser window is an action on the client side and must be caused by something in the browser. This is usually done using the enter button, but can be used inside any javascript event.
Here is an example that I pulled from existing code, additional calls were used for browser compatibility.
<input type="button" onclick="window.opener=null; window.close(); return false;" />
Also note that browsers can block this action if it is not triggered by a user action.
source share