Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start/Stop timer

Status
Not open for further replies.

JuanitaC

Programmer
Feb 21, 2001
292
CA
Hello. I have a timer script that pops up a confirm box after a while to inform the user that there has not been any activity (mousemove or keypress) in quite a while and would they like to remain, or log out. That part works great.

The tricky part is that some of my pages launch pop-up windows. I need to be able to stop the timer on the main page while the focus is in the pop-up. What I have works about half the time and I can't find any rhyme or reason to it.

Here is some of the code:
On Parent window:
<script language=&quot;javascript&quot;>
//*************** in js file included in all pages ********
if (document.layers) {
window.captureEvents(Event.MOUSEMOVE);
window.captureEvents(Event.KEYPRESS);
}
window.onMouseMove = resetTimer;
window.onKeyPress = resetTimer;

var tID = &quot;&quot;;

function stopTimer(){
//alert(&quot;timer stopped&quot;)
window.clearTimeout(tID);
}

function resetTimer(intSubID,alertTime,e) {
window.clearTimeout(tID); // reset the timer
tID = setTimeout('executeTimer('+intSubID+')',alertTime);
}

function executeTimer(intSubID) {
var boolConfirm = confirm(&quot;Some time has passed since any activity occurred in this window.\n Do you wish to continue using ePLM?\n\n Click 'OK' to continue, click 'Cancel' to log out.&quot;)
if(!boolConfirm){
window.location.href=&quot;abandon.asp?intSubID=&quot; + intSubID
}
}
//**************** end js file **********************
function newProject(){
var projWin = window.open('ProjectItem.asp?intSubID=4426&projid=&source=JFicarra','NewProject','left=10,top=10,height=480,width=780,menubar=no,resizable=no,scrollbars=yes,status=yes,toolbar=no,titlebar=yes');
}
</script>
<body onload=&quot;tID = setTimeout('executeTimer(4426)',30000);&quot; onMouseMove=&quot;resetTimer(4426,30000);&quot; onKeyPress=&quot;resetTimer(4426,30000);&quot;>

<a href=&quot;javascript:newProject();&quot;>New</a>

</body>


In the Pop-Up
<script language=&quot;javascript&quot;>
//*************** in js file included in all pages ********
if (document.layers) {
window.captureEvents(Event.MOUSEMOVE);
window.captureEvents(Event.KEYPRESS);
}
window.onMouseMove = resetTimer;
window.onKeyPress = resetTimer;

var tID = &quot;&quot;;

function stopTimer(){
//alert(&quot;timer stopped&quot;)
window.clearTimeout(tID);
}

function resetTimer(intSubID,alertTime,e) {
window.clearTimeout(tID); // reset the timer
tID = setTimeout('executeTimer('+intSubID+')',alertTime);
}

function executeTimer(intSubID) {
var boolConfirm = confirm(&quot;Some time has passed since any activity occurred in this window.\n Do you wish to continue using ePLM?\n\n Click 'OK' to continue, click 'Cancel' to log out.&quot;)
if(!boolConfirm){
window.location.href=&quot;abandon.asp?intSubID=&quot; + intSubID
}
}
//**************** end js file **********************

function window_onLoad(){
objParentWindow = window.opener;
objParentWindow.stopTimer();

tID = setTimeout('executeTimer(4426)',30000);
}
</script>
<body onload=&quot;window_onLoad()&quot; onMouseMove=&quot;resetTimer(4426,30000);&quot; onKeyPress=&quot;resetTimer(4426,30000);&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top