You are here: irt.org | FAQ | JavaScript | Pointer | Q1410 [ previous next ]
Try:
<html>
<head>
<script language="JavaScript"><!--
if (navigator.appName == 'Netscape') {
document.captureEvents(Event.MOUSEMOVE | Event.KEYDOWN);
document.onmousemove = netscapeEvent;
document.onkeydown = netscapeEvent;
}
function doit() {
timerRunning = false;
alert('hello world');
}
function netscapeEvent(e) {
if (e.screenX != document.test.x.value && e.screenY != document.test.y.value) {
if (timerRunning) {
clearTimeout(myTimer);
myTimer = setTimeout('doit()',5000);
}
document.test.x.value = e.screenX;
document.test.y.value = e.screenY;
}
}
function microsoftEvent() {
if (window.event.x != document.test.x.value && window.event.y != document.test.y.value) {
if (timerRunning) {
clearTimeout(myTimer);
myTimer = setTimeout('doit()',5000);
}
document.test.x.value = window.event.x;
document.test.y.value = window.event.y;
}
}
var myTimer = setTimeout('doit()',5000); // invoke doit() after five seconds of mouse inactivity
var timerRunning = true;
//--></script>
</head>
<body onMouseMove="microsoftEvent()" onKeyDown="microsoftEvent()">
<form name="test"><input type="hidden" name="x"><input type="hidden" name="y"></form>
</body>