#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Pennsylvania, USA
    Posts
    37
    Rep Power
    15
    I need the ability to place a timer on a page that will be generated from a cgi-script. I've found timer javascript routines, which I could imbed into the perl but with my limited javascript knowledge - I don't know if I'll be able to capture the time when the user leaves the page.
    Basically, I need the timer to not only display, but allow me to capture the elapsed time and update a database with it.
    Has anyone done something like this, or can anyone give me some advice on the best way to accomplish this?

    Thanks!
    Sharon
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    You can place a timestamp of which when the perl script is executed. But you can't capture the time when your visitor leaves the page since your script doesn't get executed anymore by doing so.
    However, you can capture the timestamp for the next visit of that particular visitor by using cookie. PHP does a better job than Perl in this case.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    179
    Rep Power
    15
    you can use the event handlers Onload and onUnload to capture the time the user loads a page and the time a user leaves the page. Afterwards, subtract the two times to find out how long the user was on the page.
    You can hold this value in a hidden form element and send it via cgi to your database.

    You'll need to become acquainted with the Date method in JavaScript.

    Hope this helps you get closer to your solution.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Pennsylvania, USA
    Posts
    37
    Rep Power
    15
    This sounds like a good solution, although I guess I would do this in addition to actually placing the javascript code there to show the representation of the incrementing time on the screen while they're visiting (a small clock window at the top of the page). My limited experience with javascript is still causing me a problem with this approach, however - how do I get the value from the calculation (difference between load and unload times) into the hidden form field in order to pass it to the cgi-script?

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by mcsimon:
    you can use the event handlers Onload and onUnload to capture the time the user loads a page and the time a user leaves the page. Afterwards, subtract the two times to find out how long the user was on the page.
    You can hold this value in a hidden form element and send it via cgi to your database.

    You'll need to become acquainted with the Date method in JavaScript.

    Hope this helps you get closer to your solution.
    [/quote]

  8. #5
  9. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>you can use the event handlers Onload and onUnload to capture the time the user loads a page and the time a user leaves the page

    You really can't with onUnload. The script doesn't get executed. Once you left the page, you no longer with it.

    >>how do I get the value from the calculation
    Let your cgi script do this dirty work.

    >>into the hidden form field in order to pass it to the cgi-script
    You have to make a form submit button with "Click here to Leave", then the hidden field can be passed to the script. If the visitor doesn't click it, the time can't be captured.
    ########################################
    Take a look at this under "Date & Time" link.. http://www.essex1.com/people/timothy/js-index.htm
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    <<<You have to make a form submit button with "Click here to Leave", then the hidden field can be passed to the script. >>>

    I think this is the viable solution for solving smmorrow's problem.




    ------------------
    SR -
    shiju.dreamcenter.net
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Pennsylvania, USA
    Posts
    37
    Rep Power
    15
    I already have a button on the page that the visitor clicks to move on to the next page. I can use this to 'stop the clock' and submit the form to the cgi-script. So, combining the unLoad to start the clock and the onClick to stop it, I should have what I need to time the visitor.
    I know I'm missing something due to my inexperience with javascript - but my main question remains: how do I get the value of a javascript variable into a form field for passing to a cgi-script?

    smmorrow
  14. #8
  15. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    If you take a look at http://www.essex1.com/people/timothy/js-index.htm under Date & Time, you should see..

    <INPUT TYPE="text" NAME="local" SIZE=16 VALUE="Current Time">

    >>how do I get the value of a javascript variable into a form field for passing to a
    cgi-script?
    As you can see that form field name is "local" but the form is <form> instead of <form method="POST" action="/cgi-bin/script.pl">
    So it's all up to your script.pl to handle the value of "local" from your 'time page' and pass it onto the next page.

IMN logo majestic logo threadwatch logo seochat tools logo