Possible Duplicate:
javascript detect browser close tab/close browser
I need to save the current time into database when shutting down the browser. Does anyone have a solution to this problem?
thanks
Possible Duplicate:
javascript detect browser close tab/close browser
I need to save the current time into database when shutting down the browser. Does anyone have a solution to this problem?
thanks
window.onunload = function() {
var time = new Date().getTime();
var xhr = new XMLHttpRequest();
xhr.open("GET", "index.php?closetime="+time, true);
xhr.send();
};
In index.php use $_GET["closetime"] and save it to database.
You can listen for the onbeforeunload
event. You can make a call to the database when this event fires. Check out this article to learn how you might use this in a cross-browser fashion.