File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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
Author

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 then...in the page:



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

Obviously I'm not passing "e" down from the page...but I'm not a JavaScript expert by any means...so 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?

Thanks!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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...

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript help - refresh page when no events are happening