javascript - calculate the time from opening the tab until closing it -
i traing calculate time when open tab until close used onload , onexit didnot work used onload , counter keep counting nothing appear on output, if 1 have solution please .
<html> <head> <script type="text/javascript"> var starttime = new date(); //start clock! window.onbeforeunload = function () //when user leaves page(closes thewindow/tab, clicks link)... { var endtime = new date(); //get current time. var timespent = (endtime - starttime); //find out how long it's been. } function timedcount() { var c = timespent + 1; t = settimeout("timedcount()", 1000); alert(c); //pop window time spent in microseconds. } </script> </head> <body> </body> </html>
this should done:
<script type="text/javascript"> var starttime = new date(); window.onbeforeunload = function () { var endtime = new date(); var timespent = (endtime - starttime); alert(timespent ); } </script>
Comments
Post a Comment