方法:1、使用setTimeout()方法關(guān)閉,語法“setTimeout("clock();",1000);”;2、窗口沒有提示自動關(guān)閉,語法“this.window.opener=null; window.close();”。
本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
第一種:JS定時自動關(guān)閉窗口
<script language="javascript"> <!-- function closewin() { self.opener=null; self.close(); } function clock() { i=i-1 document.title="本窗口將在" + i + "秒后自動關(guān)閉!"; if(i>0)setTimeout("clock();",1000); else closewin(); } var i=10 clock(); //--> </script>
第二種:窗口沒有提示自動關(guān)閉的js代碼
<script language=javascript> <!-- this.window.opener = null; window.close(); //--> </script>
擴(kuò)展資料:
IE6-7 JS關(guān)閉窗口不提示的方法
方法一:
js 代碼
function CloseWin() //這個不會提示是否關(guān)閉瀏覽器 { window.opener=null; //window.opener=top; window.open("","_self"); window.close(); }
方法二:
open.html
js 代碼
function open_complex_self() { var obj_window = window.open('close.html', '_self'); obj_window.opener = window; obj_window.focus(); }
close.html
js 代碼
window.close();
另附:
//普通帶提示關(guān)閉 function closeie(){ window.close(); } //關(guān)閉IE6不提示 function closeie6(){ window.opener=null; window.close(); } //關(guān)閉IE7不提示 function closeie7(){ window.open('','_top'); window.top.close(); }
【推薦學(xué)習(xí):javascript高級教程】