开发者

Close Window for button click

I have been trying to close the win开发者_运维知识库dow on button click but am unable to do so.

I have added javascript window.close()

added on the code behind page on button click event all in vain. Language c# or vb.net


That needs to 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 bit pointless. =)


The button click event on the code behind only handles code that affects the server side. Closing a browser window is a client side action and must be called by something on the browser. This is usually done with an input button but can be used inside any kind of javascript event.

Here is an example that I pulled out of existing code, the extra calls were used for browser compatibility.

<input type="button" onclick="window.opener=null; window.close(); return false;" />

Also of note, browsers may block this action if it is not initiated by a user action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜