Skip to content

Instantly share code, notes, and snippets.

@santosh
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save santosh/3632fe4c9a52a9c11acf to your computer and use it in GitHub Desktop.

Select an option

Save santosh/3632fe4c9a52a9c11acf to your computer and use it in GitHub Desktop.
Put time in localstorage if user visits for first time and retrieve later when the webpage was visited.
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8" />
<title> Loopingtriangle </title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
</head>
<body>
<script charset="utf-8">
if (localStorage.getItem('tim')) {
document.write("Welcome back, you visited this website earlier on " + localStorage.getItem('tim'));
}
var tim = new Date();
document.write("<br />The time now is ", +tim, " storing in your localStorage");
localStorage.setItem('tim', +tim);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment