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="javascript">
//*************** 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 = "";
function stopTimer(){
//alert("timer stopped"
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("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."
if(!boolConfirm){
window.location.href="abandon.asp?intSubID=" + 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="tID = setTimeout('executeTimer(4426)',30000);" onMouseMove="resetTimer(4426,30000);" onKeyPress="resetTimer(4426,30000);">
<a href="javascript:newProject();">New</a>
</body>
In the Pop-Up
<script language="javascript">
//*************** 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 = "";
function stopTimer(){
//alert("timer stopped"
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("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."
if(!boolConfirm){
window.location.href="abandon.asp?intSubID=" + intSubID
}
}
//**************** end js file **********************
function window_onLoad(){
objParentWindow = window.opener;
objParentWindow.stopTimer();
tID = setTimeout('executeTimer(4426)',30000);
}
</script>
<body onload="window_onLoad()" onMouseMove="resetTimer(4426,30000);" onKeyPress="resetTimer(4426,30000);">
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="javascript">
//*************** 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 = "";
function stopTimer(){
//alert("timer stopped"
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("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."
if(!boolConfirm){
window.location.href="abandon.asp?intSubID=" + 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="tID = setTimeout('executeTimer(4426)',30000);" onMouseMove="resetTimer(4426,30000);" onKeyPress="resetTimer(4426,30000);">
<a href="javascript:newProject();">New</a>
</body>
In the Pop-Up
<script language="javascript">
//*************** 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 = "";
function stopTimer(){
//alert("timer stopped"
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("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."
if(!boolConfirm){
window.location.href="abandon.asp?intSubID=" + intSubID
}
}
//**************** end js file **********************
function window_onLoad(){
objParentWindow = window.opener;
objParentWindow.stopTimer();
tID = setTimeout('executeTimer(4426)',30000);
}
</script>
<body onload="window_onLoad()" onMouseMove="resetTimer(4426,30000);" onKeyPress="resetTimer(4426,30000);">