Javascript close window or JS close Page code sharing

Source: Internet
Author: User
Tags close page

First: automatically close the window at regular JS time
Copy codeThe Code is as follows:
<Script language = "javascript">
<! --
Function closewin (){
Self. opener = null;
Self. close ();}
Function clock () {I = I-1
Document. title = "this window will be closed automatically after" + I + "seconds! ";
If (I> 0) setTimeout ("clock ();", 1000 );
Else closewin ();}
Var I = 10
Clock ();
// -->
</Script>

Type 2: Click the JS button that does not prompt to close the window
Copy codeThe Code is as follows:
<A href = "javascript: self. close ()"> close the window </a>

Third: js Code that is automatically disabled is not prompted in the window
<Script language = javascript>
<! --
This. window. opener = null;
Window. close ();
// -->
</Script>

Third: js Code that prompts information after submitting the php code window and closes the Window Automatically
Copy codeThe Code is as follows:
Document. write "<script language = javascript> alert! '); Opener = null; window. close (); </script>"

Code for automatically returning the previous page:
Copy codeThe Code is as follows:
Document. write ("<script language =" "JavaScript" "> alert (" "Your message is sent successfully. We will contact you as soon as we see it! ""); History. go (-1); </script> ")

Method of closing window without prompting for IE6-7 JS

Method 1:
Js Code
Copy codeThe Code is as follows:
Function CloseWin () // This does not prompt whether to close the browser
{
Window. opener = null;
// Window. opener = top;
Window. open ("", "_ self ");
Window. close ();
}

Method 2:
Open.html
Copy codeThe Code is as follows:
Js Code
Function open_complex_self (){
Var obj_window = your own open('close.html ',' _ self ');
Obj_1_1_opener = window;
Obj_1_1_focus ();
}

Close.html
Js Code
Copy codeThe Code is as follows:
Window. close ();

Appendix:
Copy codeThe Code is as follows:
// The error message "close" appears in the normal mode.
Function closeie (){
Window. close ();
}
// Disable IE6. No prompt
Function closeie6 (){
Window. opener = null;
Window. close ();
}
// Disable IE7. No prompt
Function closeie7 (){
Window. open ('', '_ top ');
Window. top. close ();
}

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.