0

I am trying to create a Auto Logout page for my application. I am using Javascript to handle the timer with classic asp. I have three pages the js script page, the home page where I call the js file and start the timer using OnLoad(). After 4 seconds a window pops up to ask the user to continue there session. But when the window pops up and I click yes on the logout_alert.asp page it doesn't update the timer on the home page. How can I get the popup window to update the timer? The following are the scripts.

Thanks for your help in advance,

Frank G.

I have three pages. For this example Page 1, Page 2, and Page 3.

PAGE 1 = logout_timeout.js


Here is the script for this page.

<!-- Begin

var c=0;
var t;

function ClockCount(){

c=c+1;
    //Show the clock value on the home page text field.
    document.timerform.clock.value = c;

if (c == 7) {
    //The user never responded so we will kill the session and log them out.
    alert("Your session has timed out you are logged out.");
    window.location.href = "logout.asp"
}
else if (c == 4) { 

    //We will popup a window to let the user know there about to be logged out.
    //This will give the user a chance to keep the session alive.
    logoutalert = window.open("logout_alert.asp", "logoutalert",    "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=420,height=145,left = 465,top = 250");
}

 //The timer will go round and round while recalling this function.
 t = setTimeout("ClockCount()",1000);

 }

 //Call to start the timer.
 function StartClock() {
 ClockCount();
 }

 //Called to stop the timer.
 function StopClock() {
 c=0 //Clear the timer.
 clearTimeout(t); //Stop it.
 }

 //  End -->

PAGE 2 = homepage.asp


This page I call the logout_timeout.js file to.

 <script src="logout_timeout.js" type="text/javascript"></script>
 <body OnLoad="StartClock()">
 This will show our clock while its processing.
 <form id="timerform" name="timerform" method="post" action="">
   <input type="text" name="clock" id="clock" />
 </form>
 Used now just for testing!
   <input type="submit" name="continue" id="continue" value="START" onClick="StartClock()" />
   <input type="submit" name="continue" id="continue" value="STOP" onClick="StopClock()" />

PAGE 3 = logout_alert.asp


This page pops up to notify the user that they are about to be logged out.

 <script src="logout_timeout.js" type="text/javascript"></script>
 <body>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
 <td class="Thread_Title">SESSION TIMEOUT  Alert!</td>
 </tr>
 <tr>
  <td width="85%" class="DataRows">Your session is about to timeout. Would you like to continue using WOTTS?</td>
 </tr>
 <tr>
  <td></td>
 </tr>
 <tr>
  <td></td>
 </tr>
 <tr>
  <td><form id="timerform" name="timerform" method="post" action="">
 <input type="text" name="clock" id="clock" />
 </form></td>
 </tr>
 <tr>
  <td>
   <input type="submit" name="continue" id="continue" value="START" onClick="StartClock()" />
 <input type="submit" name="continue" id="continue" value="STOP" onClick="StopClock()" />   </td>
  </tr>
  </table>
keeganwatkins
  • 3,636
  • 1
  • 14
  • 12
Frank G.
  • 1,519
  • 7
  • 25
  • 43

1 Answers1

2

You're missing a piece of the puzzle: A reference to the other window. Certain security restrictions sandbox separate window objects unless they are spawned from an existing window. If you use JavaScript's window.open () function, your new window will open with a handle to the parent that opened it. Then, in scripts, you can utilize that handle to manipulate objects and behavior and to execute functions in the parent window. This ties it all together.

There are many examples here:

Can I pass a JavaScript variable to another browser window?

Community
  • 1
  • 1
ingyhere
  • 11,818
  • 3
  • 38
  • 52
  • Hello thank you for helping. The window that has the timer in it is inside a frame. This is the code to that frame: and that frame is called "autologout" but the timer script itself is inside a js file. I share that js file between the two windows but inserting it. But I am only able to reset the timer if I have a button on that page itself. For example if I put a button on the timer page to stop the time it works but if I tell the pop up to tell the timer to stop it won't. Any suggestion? Thx! – Frank G. Feb 23 '12 at 07:44
  • You can call a function on the parent window (or frame) using window.opener, window.opener.frames[], top.opener.myFrameName.window.myFunction() ... Or, you can make a function in the child window's JavaScript that does this when you pass it the reference to the opener, like 'stopRemoteTimer (top.opener.myFrameName);' wherein you will address the actual function in the parent window that way. You'll have to do all the calculations and operations in the context of one window or another as the JS runs in its own sandbox there. – ingyhere Feb 23 '12 at 21:53