• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javascript help - refresh page when no events are happening

 
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic