Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Session Expire MSG - Help to modify

    I found this script on the web and does what I want except for one thing, if the user does not response at all it just sits & does nothing. If no response when the session time is up, I want the application to be redirect to the sign on screen.
    Here is the code I got from the web:

    Code:
    <script type="text/javascript">
            var sess_pollInterval = 60000;
            var sess_expirationMinutes = 20;
            var sess_warningMinutes = 5;
            var sess_intervalID;
            var sess_lastActivity;
    
            function initSession() {
                sess_lastActivity = new Date();
                sessSetInterval();
                $(document).bind('keypress.session', function (ed, e) {
                    sessKeyPressed(ed, e);
                });
            }
            function sessSetInterval() {
                sess_intervalID = setInterval('sessInterval()', sess_pollInterval);
            }
            function sessClearInterval() {
                clearInterval(sess_intervalID);
    
            }
            function sessKeyPressed(ed, e) {
                sess_lastActivity = new Date();
            }
            function sessLogOut() {
                window.location.href = 'SignonScreen.aspx';
            }
            function sessInterval() 
            {
                var now = new Date();
                //get milliseconds of differneces
                var diff = now - sess_lastActivity;
                //get minutes between differences
                var diffMins = (diff / 1000 / 60);
                if (diffMins >= sess_warningMinutes) 
                {
                    //warn before expiring
                    //stop the timer
                    sessClearInterval();
                    //prompt for attention
                    var active = confirm('Your session will expire in ' + 
                    (sess_expirationMinutes - sess_warningMinutes) +
                    ' minutes (as of ' + now.toTimeString() + '), press OK to remain logged in ' + 'or press Cancel to log off. \nIf you are logged off any changes will be lost.');
                    if (active == true) 
                    {
                        now = new Date();
                        diff = now - sess_lastActivity;
                        diffMins = (diff / 1000 / 60);
                        if (diffMins > sess_expirationMinutes) 
                        { sessLogOut();}
                        else 
                        {
                            initSession();
                            sessSetInterval();
                            sess_lastActivity = new Date();
                        }
                    }
                    else 
                    {sessLogOut();}
                }
            }
            
    </script>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts
    What do you mean by response?
    No button clicks, or no keyboard entry, or no mouse movement, or something else???

    How long is this non-response supposed to last? 20 minutes?

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Did you mean by no response as not clicking the OK button in the confirm dialog? You cannot do something about that. You really have to wait for the user to click the OK button.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • Users who have thanked glenngv for this post:

    godistop1 (02-17-2014)

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    you need to change the confirm() call to a "dhtml modal" or a "mode-less dialog widget" or "jsmodal" or "jqdialog". google.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #5
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    What do you mean by response?
    No button clicks, or no keyboard entry, or no mouse movement, or something else???

    How long is this non-response supposed to last? 20 minutes?

    Sorry, I left out the word NO response. Yes that is what I mean and total time for no activity is 20 minutes

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Quote Originally Posted by godistop1 View Post
    Sorry, I left out the word NO response. Yes that is what I mean and total time for no activity is 20 minutes
    the problem is that prompt() pauses the script, so it has no idea how long the dialog was open until it's closed, and there is no way to close it with js, or to schedule a reload before it shows because the script is paused.

    all you need to do is use something besides prompt() to alert the user and you can time-out the dialog.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

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