I have a web page where the data gets updated upon refresh.
I want the user to when the page has been refreshed lastly.
ie if i refresh the page after 3 sec, it should display 3 sec and so on....
Example:
var current = "08/06/2014 15:00:00"; // Current time
var next = "08/06/2014 15:00:30"; //Time after Refresh
It should output
Last seen:30 sec // (15:00:30 - 15:00:00)
Is there any way to get time after refresh using javascript??
You can use HTML5 LocalStorage
or Cookies
for storing last seen date, example(uses LocalStorage, save last page open date and show this on next loads):
window.onload = function() {
var lastSeen = localStorage.getItem("lastSeen");
if (lastSeen) {
alert("User last seen in " + lastSeen);
} else {
alert("User first time logged in page")
}
localStorage.setItem("lastSeen", new Date());
};
See this example on jsFiddle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.