如何使用php登出時刪除瀏覽器的本地存儲項目。
我想刪除所有使用php登出的瀏覽器數據。如何使用php登出時刪除瀏覽器的本地存儲項目
因爲我只想在每次登錄時顯示引導警報框,但不是在每次刷新時都顯示引導警報框。
當用戶註銷時,它將再次重置。當用戶再次登錄它會顯示。
我的代碼如下所示
$(document).ready(function() {
if(localStorage.getItem('message1') != 'shown'){
$('#message1').toggleClass('in');
window.setTimeout(function() {
$("#message1").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
});
}, 10000);
localStorage.setItem('message1','shown')
}
});
.flyover {
margin-right:-400px;
overflow: hidden;
opacity: 0.9;
z-index: 1050;
transition: all 1s ease;
position: fixed;
top: 100px;
right: 20px;
width: 300px;
z-index: 2000;
}
.flyover.in {
margin-right: 10px;
}
.alert{
color: white ! important;
}
.alert.close{
font-size: 18px ! important;
font-weight: 300 ! important;
line-height: 18px ! important;
color: white ! important;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
</head>
<body>
<div id="message1"class='alert bg-green flyover'><a href='#' class='close close-x' data-dismiss='alert' aria-label='close'><i class="fa fa-times text-white" aria-hidden="true"></i>
</a><strong>Successfully Logged In<br></strong>
<h3>Welcome, <?php echo ucwords($adminRow['admin_name']); ?></h3></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>
爲什麼不使用會話存儲,當窗口關閉時會被清除? –
告訴我如何做到這一點。這種方法會做什麼。 –
https://developer.mozilla.org/zh-CN/docs/Web/API/Window/sessionStorage –