1

I want to show user a popup if he has been there on a web page without doing any mouse clicks / keyboard press / mouse scrolling

Is there any way I can track this using javascript?

1
  • 2
    For what reason you want to detect, that's important. You can manage session or you can do it with even Javascript. Commented Feb 18, 2013 at 4:50

3 Answers 3

6
var timeout = false;
function checkActivity() {
    clearTimeout(timeout);
    timeout = setTimeout(function () { alert('inactive'); }, AmountOfTime);
}
document.addEventListener('keydown', checkActivity);
document.addEventListener('mousedown', checkActivity);
document.addEventListener('mousemove', checkActivity);
checkActivity();

What this does is run a function after AmountOfTime milliseconds. It is reset on any user activity on the document.

Sign up to request clarification or add additional context in comments.

Comments

0

You can handle Keyboard Events and Mouse Events in JavaScript.

You can have a timer counting down to when the user should be shown that message, and reset the timer whenever you get an eligible event.

Comments

0

You can use this (library)[https://github.com/mikesherov/jquery-idletimer] to detect, if the user is idle.

Example:

$(document).on('idle.idleTimer', function() {
    //do something on idle;
    });
$(document).on('active.idleTimer', function() {
    //so something on activity;
    });
$(document).idleTimer(1000, {
    startImmediately: false,
    idle: true,
    enabled: true,
    events: 'keydown' //there are more events in the docs;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.