javascript - capture user inactivity

Posted on 2007-10-15
Last Modified: 2012-05-05
We have an ASP.Net/ VB.Net web application. If the user is inactive for 5 minutes(no keystroke or mouse movement) then the user should be asked for a password again to continue using the application.

I think I can do it through javascript using a timer, but how can I have this javascript function be called from each aspx page? I think its not a good idea to copy and paste the javascript function on each aspx page. Is there a global place where I can place the javascript code & call it from each aspx page?

Please advise. Thanks in advance.
Question by:vdesai_8
    LVL 23

    Accepted Solution

    1. put the javascript in an empty text file
    2. save it as whatever.js on your webserver
    3. include it on each page like this:
    <script type="text/javascript" src="whatever.js"></script>
    LVL 26

    Expert Comment

    >> If the user is inactive for 5 minutes(no keystroke or mouse movement) then the user should be asked for a password again to continue using the application.

    A better solution would be to set the session timeout of your application as 5 minutes in your web.config

        <sessionState mode="InProc" cookieless="false" timeout="5" />

    and your code in global.asax must check whether there is a active session and if not, redirect him to the page which will ask for the password ..

    but if you have to use javascript and you want it be used in all the pages, then use a master page and every aspx page must have this page as the "master" file .. then you need to have the script  statement mentioned above ONLY in one page and that is the master page ...
    <script type="text/javascript" src="whatever.js"></script>

    this will save the effort of copying the script tag in all your aspx pages ..


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Using Quotation Marks in PHP This question ( seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
    Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now