0

Please I'd like to count the time spent on a given page. In order to do this, I need to know when the page is opened in new tab, without focus and then start counting when the tab has focus.

$(window).focus(function() {
    window_focus = true;
}).blur(function() {
    window_focus = false;
});

The above works well when the has already loaded on a focused tab. How can I know when a page is fully loaded without focus.

Overcomer
  • 318
  • 3
  • 10

1 Answers1

0

Use the setInterval for setting the tick on the focused page and clear it when it loses focus.

Duplicate of: How to tell if browser/tab is active

Community
  • 1
  • 1
Lashus
  • 379
  • 1
  • 9
  • 1
    On page load when the page is not focused on (ie, user opened the page in new tab), count begins. How do I detect that the user is not focused on the page and wait for user to focus on the page before starting count? – Overcomer Jan 14 '16 at 14:44