JS定时关闭窗口及定时提醒效果的例子

发布时间:2020-07-23编辑:脚本学堂
本文介绍下,js代码实现定时关闭窗口,以及定时提醒效果的例子,有需要的朋友,可以参考下。

例1,定时关闭窗口
 

复制代码 代码示例:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>JS定时关闭窗口-www.jb200.com</title>
<style type ="text/css" >
.main{ background-color:Silver; width :200px; height :100px; margin-left:40%; margin-top :200px; text-align :center;}
</style>
<script src="js/ui/jquery-1.7.1.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
var n = 3;
function showTime() {
n--;
$('#divMain').html(n + ' 秒后关闭窗口');
if (n == 0)
window.close();
else
setTimeout('showTime()', 1000);
}
</script>
</head>
<body onload ="showTime()">
<form id="form1" runat="server">
<div id ="divMain" class ="main" >

</div>
</form>
</body>
</html>

例2,定时关闭页面或定时提醒
 

复制代码 代码示例:
<HTML xmlns:v xmlns:t>
<HEAD>
<STYLE>v:*{behavior:url(#default#vml)}
v:oval,#oDiv{position=absolute;width=200;height=200}
#stay{position=absolute;top=70;left=59;color=RED;padding=6;font=900 20/1.3}
#input input{border-left=0;border-right=0}
</STYLE>
<TITLE>定时关闭页面或定时提醒-www.jb200.com</TITLE>
<hta:application border=none scroll=0 innerBorder=ridge>
<?import namespace=t implementation="#default#time2"/>
</HEAD>
<BODY topmargin=12 onload=resizeTo(220,240),moveTo(200,5)>
<v:oval fillcolor=#8F strokecolor=gray strokeweight=3 />
<t:par onrepeat=alt.click() repeatcount=indefinite>
<t:TRANSITIONFILTER TYPE="clockWipe" dur=60 TARGETELEMENT="oDiv"/>
<DIV ID="oDiv" DUR=60>
<v:oval fillcolor=#FF0 strokecolor=RED strokeweight=2 />
</DIV></t:par>
<a href=# id=alt></a><U id=stay unselectable=on></U>
<t:ref id=ref style=width=200;height=200 src=两只老虎.wmv mute=true clipBegin=23.8 dur=4 begin=alt.click />
<DIV>
<t:par repeatCount=indefinite>
<HR align=left id=hr0 color=TEAL width=200 size=14>
<hr onpropertychange="per=parseInt(100*offsetWidth/hr0.offsetWidth),len.innerHTML=(per>9?'':'_')+per+'%'" style=position=absolute;top=219;height=expression(hr0.size) color=BLUE id=hr dur=60>
<t:animate targetElement=hr attributeName=width id=hran from=0></t:par>
Loading persent: <a id=len style=color=red;font=800></a> .</DIV>
<dl><dt><h4>定时关闭叶面或则定时提醒:</h4>
<form name=FF><dd>请设置定时关闭叶面<br>或则定时提醒的时间:<br>
<input id=HH onmouseover=select() style=border-right=0 size=1 value=23><q id=input><input style=width=9 value=:
disabled><input id=MM onmouseover=select() size=1 value=01><input style=width=9 value=: disabled></q><input id=SS onmouseover=select() style=border-left=0 size=1 value=00><br>
<button hideFocus onclick='tips.innerHTML="窗口将于 "+FF.HH.value+":"+FF.MM.value+":"+FF.SS.value+"自动关闭...";setInterval("if(clock(FF.HH.value,FF.MM.value,FF.SS.value))window.close()",1)'>设定关闭</button><img width=5 height=1>
<button hideFocus onclick='setInterval("if(clock(FF.HH.value,FF.MM.value,FF.SS.value)){ref.mute=false;ref.dur=30;alt.click()}",1);
setInterval("if(clock(FF.HH.value,(FF.MM.value*1+1),FF.SS.value)){ref.mute=true;ref.dur=3;alt.click()}",1)'>设定提醒</button><img width=5 height=1>
<button type=reset>重新设定</button><br>
<span id=tips style='background=lightyellow'></span></dl>
</form>
<script>
hran.dur=hr.dur,hran.to=hr0.width
int=new Date(),B='<br>'
setInterval("stay.innerHTML=String(int).slice(-22,-13).fontcolor(1)+B+String(new Date(new Date()-int-288e5)).split(/ /)[3]+B+Date().slice(-13,-5).fontcolor()",1e3)
function clock(hh,mm,ss){with(new Date()) return new Date()-new Date(getYear(),getMonth(),getDate(),hh*1,mm*1,ss*1+1)==0}
</script>
</BODY>
</HTML>

例3,javascript网页关闭时提醒
当页面载入和关闭时会出现一些提示信息的代码。
 

复制代码 代码示例:

<script language=javascript>
function stoprefresh()
{
return "you will lose any unsaved content";
}

function UnloadConfirm()
{ //页面离开后的事件
alert('离开页面后的一些清理工作……');
}
</script>
<body>
<script>
window.onbeforeunload=stoprefresh; //注册关闭前的事件
window.onunload = UnloadConfirm; //注册关闭后的事件
</script>
<a href = "http://www.jb200.com">脚本学堂</a>
</body>