javascript - 如何使用php在注销时删除浏览器的本地存储项

标签 javascript php jquery twitter-bootstrap local-storage

如何使用php在注销时删除浏览器的本地存储项。

我想使用 php 删除注销时所有保存的浏览器数据。

因为我只想在每次登录时显示 Bootstrap 警报框,而不是在每次页面刷新时显示 Bootstrap 警报框。

当用户注销时,它将再次重置。当用户再次登录时,它将显示。

我的代码如下所示

$(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>

最佳答案

我的解决方案是在登录页面添加脚本标签

<script type="text/javascript">
    localStorage.clear();
</script>

关于javascript - 如何使用php在注销时删除浏览器的本地存储项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37739148/

相关文章:

javascript - 如何减少 Fabric.js 基于递归的函数中的滞后

JavaScript 全局键盘钩子(Hook)

php - 在 php 中选择另一个网站的值时如何填充下拉框的值

Jquery:错误:语法错误,无法识别的表达式:[name=someVar]

jquery - Uploadify onComplete 没有被调用

javascript - ng-click 和 ng-show 不适用于动态内容( Angular )

javascript - AngularJS:使用现有 Controller 将数据传递给指令

javascript - 将 jvectormap 连接到 ajax 访问的数据库

php - 如何使用 PHP 中的 phatomjs 在下载的页面上执行 Javascript?

php - MySQL如何在虚拟字段定义中实现条件