SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    namur
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question managing a timer between 2 frames

    Hi,
    I'm currently trying to manage a session timeout with a 2 frames window.
    In both frames I have forms, and my goal is to clear the timer and set it again every time any button on any of both frames is clicked.

    Basically, how I handle this right now is:

    In the parent's frame:

    Code:
    <head>
    <script language="Javascript">
    var timer;
    </script>
    </head>
    in the frames' forms:

    Code:
    <form name="myform" action="myaction" method="POST" onSubmit="return resetTimer();">
    the resetTimer function:
    Code:
    function resetTimer()
    {
            var timerval;
            parent.timer=clearTimeout(parent.timer);
            timerval = GetCookie("timer") * 1000;
            parent.timer=setTimeout('logout();',timerval);
    }
    Now I would expect that this would affect the same timer from both frames, but it seems to consider two seperate timers from both frames. So if I set my timer for 1 minute and that I click on a button on frame1 then wait 30 seconds, click on a button on frame2, I'll have a timeout after 30 more seconds (the 30 remaining seconds of the timer set by frame1) and it goes the same way around too...

    Anyone has a clue what I may have done wrong?

    thanks in advance

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd manage this at the server. The notion of a 'session', client-side, is pretty tenuous. Nevertheless...a few comments. This:
    Code:
    function resetTimer()
    {
            var timerval;
            parent.timer=clearTimeout(parent.timer);
            timerval = GetCookie("timer") * 1000;
            parent.timer=setTimeout('logout();',timerval);
    }
    First, clearTimeout doesn't - afaik - return anything, so you can safely lose the 'parent.timer=' bit. Secondly - this is probably related to your problem - variable scope can get tricky, from browser to browser, when scripting cross-frame/window. parent.timer=setTimeout('logout();',timerval); should probably be parent.timer=parent.setTimeout('logout();',timerval);. Assuming 'logout()' is defined in the parent.

    Naturally, this gets scoped explicitly as well:
    Code:
    parent.clearTimeout(parent.timer);
    Have no idea if this will work.
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    Mar 2004
    Location
    namur
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This seems to work...

    Thank you so much, I spent my whole day posting in forums everywhere to find someone who could help me... guess now I might just post the answer everywhere too ;-)

    I'll come again for sure

    edit: Note that I also had to move the declaration of the logout() function in the parent window


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •