简体   繁体   中英

close window in button click using javascript

I'm creating message dialogue box using JavaScript alert statement. That dialogue box contains one button. In that button click i want to close the current window.

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 only close the window when i click the image button. But i want to close the window in button click of the dialogue box

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

If I understood you question properly, you want to close your parent windown from dialog box. Though the code you have written will close your dialog box and not your parent window. To close your parent window, you can use below code:

window.opener.close();

如果您想关闭父窗口,则应该像这样更改代码

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM