This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes javascript help - refresh page when no events are happening Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript help - refresh page when no events are happening" Watch "javascript help - refresh page when no events are happening" New topic

javascript help - refresh page when no events are happening

Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I've been goofing around w/ trying to build a script that will refresh a web page *if* there is no activity happening on the page. For example; if someone is typing into one of the form fields or clicking something...I don't want the page to refresh and wipe out what they're doing...but if there *is* no activity...I'd like the page to refresh every 30 seconds or so.

I tried doing something like this:

which is called by this function:

...and the page:

NOTE: I had to rename it to on1oad because of the's an intentional type.

Obviously I'm not passing "e" down from the page...but I'm not a JavaScript expert by any I'm not sure how I would get "e" from the top level down...

The page is refreshing but it doesn't *stop* refreshing if I'm typing into the form...and I need it to stop if an event is occuring...and the timer should start over once no events are detected. I've been fooling w/ this thing for hours and just can't spend any more time on it...anyone have some clues for me?

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
You need to call a function to get key presses with an onkeypress, onkeyup, or onkeydown. You can not get it through a timer like that.

What you need to do is have a key listener on the page and have it update a global boolean. When a key is typed set it to true.

Have a timer check the Boolean value. If true reset it to false and wait again. If false then you know nothing happened.

You may want to look into an Ajax method instead...

I agree. Here's the link:
subject: javascript help - refresh page when no events are happening
It's not a secret anymore!