Close button click window

I try to close the window when I click the button, but I can not do this.

I added javascript window.close()

added to the code after page on the button click event everything is in vain. c# or vb.net language

+4
source share
2 answers

This should be on the client side, try something like this:

 <input type="button" id="close" onclick="window.close()" /> 

If you want an asp.net button, you can do:

 <asp:Button ID="close" runat="server" OnClientClick="javascript:window.close()" /> 

Although that would be a little pointless. =)

+11
source

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.

+3
source

All Articles