Home > Web Front-end > JS Tutorial > body text

How to automatically close the window with javascript

醉折花枝作酒筹
Release: 2021-07-22 10:44:24
original
4154 people have browsed it

Method: 1. Use the setTimeout() method to close, with the syntax "setTimeout("clock();",1000);"; 2. The window will automatically close without prompts, with the syntax "this.window.opener=null ; window.close();".

How to automatically close the window with javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The first type: JS automatically closes the window at a scheduled time

Copy after login

The second type:The window does not prompt the js code for automatic closing

Copy after login

Extended information:

IE6-7 JS method to close the window without prompting

Method 1:

js code

function CloseWin() //这个不会提示是否关闭浏览器    
{    
window.opener=null;    
//window.opener=top;    
window.open("","_self");    
window.close();    
}
Copy after login

Method two:

open.html

js code

function open_complex_self() {    
  var obj_window = window.open('close.html', '_self');    
  obj_window.opener = window;    
  obj_window.focus();    
 }
Copy after login

close.html

js code

window.close();
Copy after login

Attached:

//普通带提示关闭
function closeie(){
window.close();
}
//关闭IE6不提示
function closeie6(){
window.opener=null;
window.close();
}
//关闭IE7不提示
function closeie7(){
window.open('','_top');
window.top.close();
}
Copy after login

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to automatically close the window with javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!