I am new ish to jQuery and have been trying to figure things out myself but I am being left with some questions and would like clarification when it comes to the problems I am facing. I am trying to test if a page is currently active using jQuery. At the moment, I have a page with a header and footer that stays in place and another page nested into the body portion of the page. So in other words, I have a page nested in a page.
Right now, I have the following code to test if a page is still active:
$(document).on("click mousemove keydown", function () {
activity = true;
});
I have other code later on that takes this information and sends a heartbeat to keep the page alive. My problem is this: Right now this only tells me if the user is moving around or clicking in the header or footer and not in the partial that is in the body.
I found another stackoverflow page(link at bottom) that worked with nested $(document).ready() but I have questions about if this would work in my case. Does this nested $(document).ready() actually read the item below it or it just tells us a second time that the same page is ready? And if it does tell us if the inner page is ready, in my example, would I just need to wrap it in one $(document).ready() since I use the $(document).on() to test the inner page?
Difference between nested $(document).ready() and $(window).load() events
Edit:
I ended up putting the check for activity on the individual pages before using the page as the IFrame. It was a huge work-around but it ended up working as I needed it to.
The only other option I had found that would sorta work was to check if the user went into the IFrame (by checking what was blurred) and if the mouse didn't move positions on the page for a set amount of time, that is when the user was considered inactive. This wasn't enough in my case so I couldn't just do this option.