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> |