Show time spent on a site when they leave
|
Author: Mattias (mattias@problem.se) Categories: Javascript |
|
|
|
|
|
The tutorial: Digg this, Post to del.icio.us, Javascript can be used for lots of things. I got this idea some minutes ago and thought that I write it down for more people to use. The reason I thought about this, is that I wondered how long time I spent reading an other tutorial :-) I don't know if the function in it self is useful on a serious website, but I think that you can use the function to build special things for your needs. Ok,now lets get to the magic... This is separated in two parts. On part that is activated when you visit the page, and one part that is activated when you leave the page.
This part is made up of three parts.
leavingPage-functionA simple explanation of what the function does. On a date object we have lots of different functions, and we will use three of them to get seconds, minutes and hours. Probably the person will never stay one hour, but youget the point hehe :-) This row: "time = (seconds + (minutes * 60) + (hours * 60 * 60);" get the number of seconds from the start to the time the visitor leave. After that I just do a small thing for fun... (I guess that I am a little bit bored when I consider that fun..., but anyway). We do a check if the visitor has been at the site more than one minute and show a message that thank the visitor. If the visitor has been at the site less than 60 seconds theyget a message that they should stay longer next time. Hope you find this useful for something, or atleast good for learning :-) Digg this, Post to del.icio.us, |
