js检测 鼠标点击,如果超过一定时间,则自动退出.
<html>
<head>
<title>鼠标移动监测</title>
<script language="JavaScript">
try{var old = event.x}
catch(e){}
function test()
{
if (old==event.x)
{
document.all.ospan.innerText = "鼠标没有动静了?"
}
if (old>event.x)
{
document.all.ospan.innerText = "鼠标向左移了"
}
if (old<event.x)
{
document.all.ospan.innerText = "鼠标向右移了"
}
old = event.x
}
</script>
</head>
<body οnmοusemοve="test()">
<span id="ospan"></span>
</body>
</html>
<body οnlοad="hiddenButton()">
<button name="btn" time="10">10秒</button>
<button name="btn" time="16">16秒</button>
<button name="btn" time="9">9秒</button>
<button name="btn" time="3">3秒</button>
<button name="btn" time="5">5秒</button>
<button name="btn" time="38">38秒</button>
<button name="btn" time="12">12秒</button>
<button name="btn" time="23">23秒</button>
<button name="btn" time="8">8秒</button>
<button name="btn" time="4">4秒</button>
<div id="text"></div>
</body>
<script>
var btn = document.getElementsByName("btn");
var time = 0;//页面停留时间数
var count = 0;//已隐藏按钮数
function hiddenButton(){
for(var i =0;i<btn.length;i++){
if(btn[i].time<=time && btn[i].style.display !="none"){
btn[i].style.display = "none";
count++;
}
}
time++;
document.getElementById("text").innerHTML = "本页面已打开"+time+"秒,已隐藏"+count+"个按钮";
setTimeout("hiddenButton()",1000);
}
</script>
--------------------js监听用户操作----------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<SCRIPT language="JavaScript">
var timerIdle=0; //空闲时间
var timerBusy=0; //倒计时开始
var timerIdle1=2; //系统参数定义超时时间
var timerBusy1=30; //退出时间
function timerTimeout()
{
timerIdle++;
if (timerIdle>timerIdle1)
{
if (timerBusy==0)
{
timerBusy=timerBusy1+1;
//view timerUI
document.getElementById("timerUI").style.display="inline";
}
timerBusy--;
//view timerBusy
document.getElementById("_timerBusy").innerHTML=timerBusy;
if (timerBusy<=0)
{
timerExit();
return;
}
}
else
{
timerBusy=0;
}
window.setTimeout("timerTimeout()",1000);
}
function timerUser()
{
//让div消失
timerIdle=0;
document.getElementById("timerUI").style.display="none";
}
function timerExit()
{
//超时处理.这里可以写自己需要执行的方法...
document.getElementById("_timerBusy").innerHTML="Timeout";
}
window.setTimeout("timerTimeout()",1000);
function mouseMove(ev)
{
ev= ev || window.event;
timerUser();
var mousePos = mouseCoords(ev);
}
function mouseCoords(ev)
{
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
document.onmousemove = mouseMove;
document.onkeydown = mouseMove;
</SCRIPT>
</head>
<body>
<DIV ID="timerUI" style="position:absolute; left:30px; top:30px; font-size:20px;">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td nowrap align="right"><img src="images/loading/6.gif"></td>
<td nowrap align="right" ID="_timerBusy" style=" font-size:36px; font-weight:bold; color:#FF0000;"></td>
<td nowrap align="left"> 秒后将退出系统</td>
</tr>
<tr>
<td nowrap align="right"></td>
<td nowrap align="right"></td>
<td nowrap align="left"> 如继续操作点任意键即可</td>
</tr>
<tr>
<td nowrap align="right"></td>
<td nowrap align="right"></td>
<td nowrap align="left"> (系统检测到您长时间未进行任何操作,为保护您的信息安全将自动退出)</td>
</tr>
</table>
</DIV>
</body>
</html>