SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question what function to use???

    hey people,

    i got some scripts about timing ... namely it's a particular amount of time set, after which a one rederected to another (secure part) ....

    The question is: What function to use to get the page redirected if one doesn't move mouse or type anything (in short if one doesn't interact at all). but in case he/she does the time starts out from the very beginning.

    for instance: the time starts from 30 and all the way down 29, 28 and so on ... and it keeps counting til 0, after which another page appears. It happens only in case of no interaction. Otherwise it begins counting from 30 again.

    thanks for help and any suggestions in advance.

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is an example of one way you could do it:
    <html>
    <head>
    <title>Redirect After set time</title>
    <script language="javascript">
    var counter=30
    function Redirect()
    {
    document.page_time.timerdis.value=counter
    counter--
    if(counter<=0)
    {location.href="page1.html"}
    setTimeout("Redirect()",1000)
    }
    function Resetcount()
    {
    counter=30
    }
    if(document.getElementById&&!document.all) // for ns6+ only
    {document.captureEvents(Event.MOUSEMOVE)}
    document.onmousemove=Resetcount
    </script>
    </head>
    <body onLoad="Redirect()">
    <br><br>
    <center>
    <form name="page_time">
    <input type="text" name="timerdis" size="3">
    </form>
    </center>
    </body>
    </html>

  3. #3
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey requestcode,

    thanx for the code above ... but u know man it kinda doesn't start counting down if the mouse is within the page. it does if only a cursor is out of page (for ex. on the menu bar or on the task bar).

    But what's the event if you want the time to start counting if a cursor doesn't move within the page (white area)?

  4. #4
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you talking about OnLoad? OnLoad will fire a function immediately after the page loads.

  5. #5
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great ... it's working ... !!!

    thanx to all.

    by the way, what's the function that controls keyboard (as onmousemove but for keyboard)?

    thanks

  6. #6
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's OnKeyUp (fires a function when a key is released), OnKeyDown (fires a function when a key is pushed down), and OnKeyPress (fires a function when a key has been pushed down and then up).

  7. #7
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would the piece of code be like that
    ----
    ----
    function Resetcount()
    {
    counter=10
    }
    if(document.getElementById&&!document.all)
    {document.captureEvents(Event.MOUSEMOVE)}
    document.onmousemove=Resetcount
    document.onkeypress=Resetcount
    ---
    ---

    If so, then it doesn't work. can you please look it up.

    thanks


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
  •