关闭窗口按钮单击使用JavaScript

时间:2012-08-31 04:29:02

标签: javascript asp.net button click vb.net-2010

我正在使用JavaScript警告语句创建消息对话框。该对话框包含一个按钮。在该按钮单击我想关闭当前窗口。

的JavaScript

<script language="javascript" >
     function Confirmation() {
         var win = window.open('', '_self');
         if (confirm("Are you sure you want to close the form?") == true)
             win.close();
         else
             return false
     }

  </script>

HTML

 <td class="style5">
<asp:ImageButton ID="close" runat ="server" ImageUrl ="image/button_blue_close.png" OnClientClick="return Confirmation()"
        Height="16px" Width="21px" ImageAlign="Right"/>
 </td>

我的代码仅在单击图像按钮时关闭窗口。但我想通过按钮单击对话框关闭窗口

 my code in vb.net
 -----------------
 ClientScript.RegisterStartupScript(Me.GetType(), "message", "alert('Please Raise the  ticket for particular event');", True)

2 个答案:

答案 0 :(得分:0)

如果我理解你的问题,你想要从对话框关闭你的父窗口。虽然您编写的代码将关闭对话框而不是父窗口。要关闭父窗口,可以使用以下代码:

window.opener.close();

答案 1 :(得分:0)

如果要关闭父窗口,则应该更改代码

`<script language="javascript" >function Confirmation(){if (confirm("Are you sure you want to close the form?") == true) window.opener.close();else return false;}</script>`
相关问题