locked
jquery reset the application session time based on mouse click and scroll RRS feed

  • Question

  • User-1821202846 posted

    I am at present using a session state time out based on the value from my web config this works at present but we want to trap mouse click on page or a scroll to reset the timer is this possible at all and if so what is the best way of doing that

       
     <script type="text/javascript">
    function SessionExpireAlert(timeout) {
        var seconds = timeout / 1000;
        document.getElementsByName("secondsIdle").innerHTML = seconds;
        document.getElementsByName("seconds").innerHTML = seconds;
        setInterval(function () {
            seconds--;
       //     document.getElementById("seconds").innerHTML = seconds;
       //     document.getElementById("secondsIdle").innerHTML = seconds;
        }, 1000);
        setTimeout(function () {
            //Show Popup before 20 seconds of timeout.
            $find("mpeTimeout").show();
        }, timeout - 20 * 1000);
        setTimeout(function () {
            
    
            window.location = "https://portal.aperturenet.co.uk/myaccount/logout.aspx";
        }, timeout);
    };
    function ResetSession() {
        //Redirect to refresh Session.
        window.location = window.location.href;
    }
         </script>
    

    How would I go about to trigger a mouse scroll and the click we want the session to restart the timer I have some c# page  code

      if (!this.IsPostBack)
      {
                    Session["Reset"] = true;
                    Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
                    SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
                    int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
                   Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
      }

    Friday, October 7, 2016 2:19 PM

Answers

  • User283571144 posted

    Hi rogue1,

    Tjhat is not what I asked I asked how would i track mouse click and mouse scroll in my existing code mazhar that example is irellivant

    According to your description, I suggest you could use jquery click method to track mouse click and use on method to bind mouse scroll event to html elements.

    More details, you could refer to follow link and codes:

    JS:

     <script src="../scripts/jquery-1.12.4.min.js"></script>
        <script>
            $(function () {
                $("body").click(function () {
                    alert("aaa");//here fire your js function
                });
                $('body').on('DOMMouseScroll mousewheel', function (e) {
                    if (e.originalEvent.detail > 0 || e.originalEvent.wheelDelta < 0) { //alternative options for wheelData: wheelDeltaX & wheelDeltaY
                        //scroll down
                        alert("down");//here fire your js function
                    } else {
                        //scroll up
                        alert("up");//here fire your js function
                    }
                    //prevent page fom scrolling
                    return false;
                });
            });
        </script>

    Html Makeup:

    <body>
        <form id="form1" runat="server">
        <div>
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        </div>
        </form>
    </body>

    Link:

    Click method:

    https://api.jquery.com/click/

    On method:

    http://api.jquery.com/on/

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 10:11 AM

All replies

  • User-471420332 posted

    Dear rogue1.

                         You can used below example also.

    http://www.aspdotnet-suresh.com/2012/06/jquery-show-session-timeout-message.html

    Friday, October 7, 2016 2:49 PM
  • User-1821202846 posted

    Tjhat is not what I asked I asked how would i track mouse click and mouse scroll in my existing code mazhar that example is irellivant

    Friday, October 7, 2016 3:04 PM
  • User283571144 posted

    Hi rogue1,

    Tjhat is not what I asked I asked how would i track mouse click and mouse scroll in my existing code mazhar that example is irellivant

    According to your description, I suggest you could use jquery click method to track mouse click and use on method to bind mouse scroll event to html elements.

    More details, you could refer to follow link and codes:

    JS:

     <script src="../scripts/jquery-1.12.4.min.js"></script>
        <script>
            $(function () {
                $("body").click(function () {
                    alert("aaa");//here fire your js function
                });
                $('body').on('DOMMouseScroll mousewheel', function (e) {
                    if (e.originalEvent.detail > 0 || e.originalEvent.wheelDelta < 0) { //alternative options for wheelData: wheelDeltaX & wheelDeltaY
                        //scroll down
                        alert("down");//here fire your js function
                    } else {
                        //scroll up
                        alert("up");//here fire your js function
                    }
                    //prevent page fom scrolling
                    return false;
                });
            });
        </script>

    Html Makeup:

    <body>
        <form id="form1" runat="server">
        <div>
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        aaa
            <br />
        </div>
        </form>
    </body>

    Link:

    Click method:

    https://api.jquery.com/click/

    On method:

    http://api.jquery.com/on/

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 10:11 AM
  • User-1821202846 posted

    Brando how would one modify the above jquery to reset the asp.net session variable it is that im using to time out with thanks very much for your kind example

    Monday, October 10, 2016 1:00 PM