Several ways to close page pages in JavaScript

Source: Internet
Author: User
Tags close page php code

The first type: JS timed automatically close the window

The code is as follows Copy Code
<script language= "JavaScript" >
<!–
function Closewin () {
Self.opener=null;
Self.close ();}
function Clock () {i=i-1
document.title= "This window will be automatically closed after" +i+ "seconds!";
if (i>0) settimeout ("clock ();", 1000);
else Closewin ();}
var i=10
Clock ();
–>
</script>

The second: Click the link does not prompt JS close the window

The code is as follows Copy Code
<a href= "Javascript:self.close ()" > Close window </a>

The Third Kind: The window does not have the prompt to automatically close the JS code

The code is as follows Copy Code
<script language=javascript>
<!–
This.window.opener = null;
Window.close ();
–>
</script>

The fourth kind: The PHP code submits the window after prompts the information and automatically closes the window the JS code

The code is as follows Copy Code
document.write "<script language=javascript>alert" (' Your message sent successfully, we see in time to contact you! '); Opener=null;window.close ();</script> "

Automatically returns the previous page's code:

The code is as follows Copy Code
document.write ("<script language=" "JavaScript" ">alert" "your message sent successfully, we see you in time to contact!" ""); History.go ( -1);</script> ")

Ie6-7 JS Close the window does not prompt the method
method One: JS code

The code is as follows Copy Code
function Closewin ()//This does not prompt you to close the browser
{
Window.opener=null;
Window.opener=top;
window.open ("", "_self");
Window.close ();
}

Method Two: Open.html,js code

The code is as follows Copy Code
function Open_complex_self () {
var Obj_window = window.open (' close.html ', ' _self ');
Obj_window.opener = window;
Obj_window.focus ();
}
Close.html

JS Code
Window.close ();

The code is as follows Copy Code

Also attached:
Normal with tips off
function Closeie () {
Window.close ();
}
Close IE6 do not prompt
function Closeie6 () {
Window.opener=null;
Window.close ();
}
Close IE7 do not prompt
function Closeie7 () {
window.open (", ' _top ');
Window.top.close ();
}


Automatic shutdown of web pages without prompting

The code is as follows Copy Code
<script language= "JavaScript" >
<!–
function Closewin () {
SetTimeout ("Self.close ()", 5000)
}
–>
<body onload= "Closewin ()" >
The key here is settimeout ("Self.close ()", 5000), which causes the window to close after 5000 milliseconds, but the experiment found that in 5 seconds it will appear a dialog box asking the user whether to close the page, you say it so much nonsense ~ Quack
Seriously, the problem is still to be solved. Look at the code below.
function Close2 () {
Window.opener=null;
SetTimeout ("Self.close ()", 5000);
}
<input type= "button" value= "Close" onclick= "Close2 ()" >
Save as a Web page, click the button, 5 seconds later, the page automatically closes, and there is no hint. The difference in this sentence window.opener=null
The following code is a new window with a controllable size that pops up after the page is opened and then the old window closes automatically after 2 seconds. Here the 2 seconds can be set to a shorter time, close to and directly open a controllable size and have a borderless, address bar, etc. window, in some cases may be appropriate.
<script language= "JavaScript" >
function Open1 ()
{
window.open (' http://127.0.0.1/index.asp ..., ', ' toolbar=no,menubar=no,location=no,height=650,width=980′);
}
<body onunload= "Open1 ();" >
<script language= "JavaScript" >
Window.settimeout (window.close,2000);
Window.opener=null
And the new window, n seconds after the new window automatically closed is simple, just add in the new window
<script language= "JavaScript" >
SetTimeout ("Window.close ()", 2000);

The 34th piece of code resolves the pop-up window Hofu window and the child window silently automatically closes.

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.