Close the current window using JavaScript

Source: Internet
Author: User

<Script language = "javascript" type = "text/javascript">
Function getconfirm ()
{
If (confirm ("do you want to disable it? ") = True)
{
Window. close ();
Return true;
}
Else
{
Return false;
}
}
</Script>

<Asp: Button ID = "Btn_Close" runat = "server" Text = "close" Width = "103px" OnClick = "Btn_Close_Click" OnClientClick = "return getconfirm ()"/>

In this case, when you click the close button, "Do you want to close it?" will pop up ?" But when you click "yes", another message box "the page you view is attempting to close the tab. Close the tab ?".

Here is a solution:

 

<Script language = "javascript" type = "text/javascript">
Function getconfirm ()
{
If (confirm ("do you want to disable it? ") = True)
{

Window. open ('', '_ parent ','');
Window. top. opener = null;
Window. close ();
Return true;
}
Else
{
Return false;
}
}
</Script>

<Asp: Button ID = "Btn_Close" runat = "server" Text = "close" Width = "103px" OnClick = "Btn_Close_Click" OnClientClick = "return getconfirm ()"/>

In this way, the current tab is closed directly, and another message box is no longer displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.