Window. close window prompts Usage Details

Source: Internet
Author: User

Window. close is used in js to close the window without any other usage. Next I will briefly introduce some tips for window. close () to close the window.

When window. close is used to close the window opened by, a prompt window is displayed, but the window opened by window. open () is not. However
Window. open ("about: blank", "_ self"). close ()

Avoid this problem.

Likewise,

The Code is as follows: Copy code

Window. parent. close ()

And

Window. top. close ()

Can be written

Window. open ("about: blank", "_ parent"). close ()
And

Window. open ("about: blank", "_ top"). close ()

This avoids this problem.

It is easy to remove this prompt box in the program, but it is slightly different in IE6 and IE7.

1. IE6

The Code is as follows: Copy code
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> IE6Close </title>
<Script type = "text/javascript">
Function closeWin ()
{
Window. opener = null;
Window. close ();
}
</Script>
</Head>
<Body>
<Form id = "form2" runat = "server">
<Div>
<Input id = "btnClose" type = "button" value = "close" onclick = "closeWin ()"/>
</Div>
</Form>
</Body>
</Html>

2. IE7

The Code is as follows: Copy code
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> IE7Colse </title>
<Script type = "text/javascript">
Function closeWin ()
{
Window. open ('', '_ self ','');
Window. close ();
}
</Script>
</Head>
<Body>
<Form id = "form2" runat = "server">
<Div>
<Input id = "btnClose" type = "button" value = "close" onclick = "closeWin ()"/>
</Div>
</Form>
</Body>
</Html>

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.