Why not just store the date/time of their last activity? Everytime they do something on your site, update the date/time field in the database and then when they leave, you can just say that their last activity time was the time they left. That will help if they choose not to logout.
Otherwise, if they logout you have no problem, just log the time they logout. But in actuality, the time they log out may not be the time they leave your site. They could surf around your site after they've logged out, assuming you allow that. If you want to pick hairs, you should store their IP address in a seperate table in a database and then, regardless whether they are logged in or not, you just keep track of the last activity time for that given IP address. When it quits changing, assume that is when they left your site. Of course, without using some client-side mumbo jumbo like JavaScript, you cannot truly ascertain that they have left your site, because the page could always still be open.
Hope that gives you some ideas. Sorry for not helping more with a JavaScript solution but like you've already noticed, JavaScript can be disabled so it is not good to rely on it. Personally, I never use JavaScript because I prefer everything to run server-side. It does make things a little more difficult at times, but hey... isn't that what being a programmer is all about. 😉
Aaron Zoller
www.AaronZoller.com (Opening in June)