SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting an event after X seconds

    Hello,

    I'm trying to figure out how to detect an onclick event that occur sometime in the 5 seconds after an onclick event (both events on the same element)? I've tried something with setTimeout or setInterval, but I can't think of anything to make this work

    Any ideas?
    Thank
    /(bb|[^b]{2})/ - Shakespeare.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    javascript time

    Maybe you could use the Date() object? eg.
    // var to hold time
    // event code {
    // get time from Date obj
    // if "now" time - "then" time is < value
    // do stuff
    // else
    // do other stuff

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mittineague, that will do.
    Is there any other way doing this with setTimeout or setInterval?

    Edit:
    My fault: I need to check for an ondblclick and then for onclick, both for the same element.
    If both events were the same it would be easier (I managed to do that, but with 3 global variables), but that's not the case.

    Can anyone think of a way to do this?
    Last edited by b_hole; Sep 17, 2007 at 23:58.
    /(bb|[^b]{2})/ - Shakespeare.

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Store the variables in the element instead of globally.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •