자바스크립트 로그아웃 구현
-
게시물 수정 , 삭제는 로그인 필요
회원가입하고 로그인까지 구현했는데 홈페이지에서 로그아웃을 구현하는 법을 모르겠어요 아래코드는 회원가입 html, js 로그인 html, js 홈페이지html 입니다
회원가입html
<!DOCTYPE html>
<html>
<head>
<title>.</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/join.css">
</head>
<body>
<div class="login-form">
<button type="button" class="back" value="" onClick="history.go(-1)">
<img src="images/arrow.png">
</button>
<form action="" method="post" name="member">
<input type="text" name="email" class="email" id="email" placeholder="이메일"> @
<input type="text" name="email2" class="email2" id="email2">
<select name="sel_addr" id=sel_addr onchange="sel_email()">
<option value="">직접입력</option>
<option value="naver.com">naver.com</option>
<option value="hanmail.net">hanmail.net</option>
<option value="gmail.com">gmail.com</option>
</select>
<input type="password" name="password" class="pwd" id="pwd" placeholder="비밀번호">
<input type="password" name="password" class="repwd" id="repwd" placeholder="비밀번호확인">
<input type="button" onclick="form_check(this.form)" class="submit-btn" value="회원가입">
</form>
</div>
<script src="js/join.js"></script>
</body>
</html>
회원가입 js
function form_check(){
var email=document.getElementById("email").value;
var email2=document.getElementById("email2").value;
var pwd = document.getElementById("pwd").value;
var repwd = document.getElementById("repwd").value;
var emailsum=document.getElementById("email").value + '@' + document.getElementById("email2").value;
sessionStorage.setItem("emailsum", emailsum);
sessionStorage.setItem("pwd", pwd);
if(!email){
alert('이메일주소를 입력해주세요.');
email.select();
return false;
}
else if(!email2){
alert('이메일주소를 입력해주세요.');
email2.select();
return false;
}
else if(!pwd){
alert('비밀번호를 입력해주세요.');
pwd.select();
return false;
}
else if(pwd != repwd){
alert('비밀번호를 정확히 입력해주세요.');
repwd.select();
return false;
}
else if(pwd.length < 4 || pwd.length > 12){
alert("비밀번호는 4~12자로 구성해 주세요.");
pwd.select();
return false;
}
else{
alert('회원가입이 완료되었습니다.');
window.open('login.html',"_self");
}
}
function sel_email(){
//alert("test");
var sel_addr = document.getElementById("sel_addr");
var a = sel_addr.options.selectedIndex;
var b = sel_addr.options[a].value;
email2.value = b
}
로그인 html
<!DOCTYPE html>
<html>
<head>
<title>.</title>
<meta charset="utf-8">
<link href="css/login.css" rel="stylesheet">
</head>
<body>
<div class="login-form">
<button type="button" class="back" value="" onClick="history.go(-1)">
<img src="images/arrow.png">
</button>
<form>
<input type="text" name="login_emailsum" id="login_emailsum" class="login_emailsum" placeholder="이메일">
<input type="password" name="login_pwd" id="login_pwd" class="login_pwd" placeholder="비밀번호">
<input type="button" onclick="submit_btn(this.form)" class="submit-btn" value="로그인">
</form>
<div class="join">
<a href="join.html">회원가입</a>
</div>
</div>
</body>
<script src="js/login.js"></script>
</html>
로그인 js
function submit_btn(){
var emailsum = sessionStorage.getItem("emailsum");
var pwd = sessionStorage.getItem("pwd");
var login_emailsum = document.getElementById("login_emailsum").value;
var login_pwd = document.getElementById("login_pwd").value;
if(!login_emailsum){
alert('이메일주소를 입력해주세요');
login_emailsum.select();
return false;
}
else if(!login_pwd){
alert('비밀번호를 입력해주세요.');
login_pwd.select();
return false;
}
else if (emailsum === login_emailsum && pwd === login_pwd) {
window.open('home.html',"_self");
}
else {
alert('로그인 실패. 이메일 또는 비밀번호를 확인하세요.');
}
}
홈 html (home.html)
<!DOCTYPE html>
<html>
<head>
<title>.</title>
<meta charset="utf-8" />
<link href="css/h.css" rel="stylesheet" />
</head>
<body>
<ul id="menu">
<li><a href="login.html">login</a></li>
</ul>
</body>
</html>
#자바스크립트 로그아웃 #자바스크립트 로그인 로그아웃 #자바스크립트 자동 로그아웃