Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=windows-1252">
<title>Page Title</title>
</head>
<body>
<script>
var loginSession = localStorage.getItem('loginSession');
//Sample Login Function
function login(){
//Set login session = 1 after a successful login
localStorage.setItem('loginSession', 1);
}
//Sample Logout Function
function logout(){
//Set login session = 0 after a successful logout
localStorage.setItem('loginSession', 0);
}
function checkSession(){
var loginSession = localStorage.getItem('loginSession');
if(parseInt(loginSession) !== 1){
alert('Logged Out');
console.log("Session Status: LoggedOut");
location.reload();
}
else
console.log("Session Status: LoggedIn");
//Check session in every 300 ms
setTimeout("checkSession()", 500);
}
//login
if(loginSession === null) login();
//intiate session check
checkSession();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.