Have no idea how to make it :( I think javascript should be used, any suggestions?
+1
A:
Something like this?
var startDate = new Date();
window.onbeforeunload = function() {
var millSecsOnPage = new Date() - startDate;
// ajax save this value
};
David Hedlund
2009-11-30 15:40:14
OMG...I tihnk I'm too tired, think I need a rest :( Thanks!
pedro
2009-11-30 17:13:23
A:
You need to post from the client side two times:
- First window.onload - when the user started viewing the page, tough you might be able to do it internally on your PHP/ASP server code. This might get broken by cache.
- When the user leaves - this is a must window.onclose.
Just post back an empty post - you only need to know the IP and the lookup for the previous time recorded.
... or... use Google Analytics. 2 minutes of work.
Edit: I see d's code. This is the first answer I gave you - but be warned, that without JavaScript - this cannot be done.
Edit2: Instead of using window.load, the post/get should be done in the header or in the . That php "js" can also be an empty file - you just need it to record the event.
elcuco
2009-11-30 15:42:12
I'm not sure that window.onload is necessarily the best event to start measuring from, I'd measure it from when the script is executed. If you have a picture that takes 30 seconds to load, should the user's visit not be considered to start until the picture has loaded? In general I'd say it should start as soon as the HTML is being rendered.
Andrzej Doyle
2009-11-30 15:50:39
You are so right, the programmer should post as soon as <body> is opened, or inside the <head>. I totally agree.
elcuco
2009-11-30 16:30:30