我想记录网页打开和关闭的日期和时间。将数据存储在txt文件中,例如:开始日期时间,结束日期时间
<script type="text/javascript">
var startTime = new Date(); //Start the clock!
window.onbeforeunload = function() //When the user leaves the page(closes the window/tab, clicks a link)...
{
var endTime = new Date(); //Get the current time.
var timeSpent=(endTime - startTime); //Find out how long it's been.
alert(timeSpent); //Pop up a window with the time spent in microseconds.
}