如何使用过期会话弹出窗口

How can i make a popup with expire session

本文关键字:窗口 会话 何使用 过期      更新时间:2023-09-26

我在导航的每个页面上都会出现一个图像弹出窗口。

我需要知道如何才能让它消失,如果我点击关闭,它就不会在那个会话中再次出现。

  <body onclick="document.getElementById('anuntImportant').style.display='none'">
      <div id="anuntImportant" style="position: absolute; top:30%;left:40%; display:block;overflow:visible; z-index:1000">
          <img src="image/data/program-sarbatori.jpg">
      </div>
  </body>

您可以使用sessionStorage进行以下操作:

function hide() {
  document.getElementById('anuntImportant').style.display='none';
  if (window.sessionStorage) {
    sessionStorage.setItem('hideAnuntImportant', true);
  }
}
window.onload = function() {
  if (window.sessionStorage) {
    if (JSON.parse(sessionStorage.getItem('hideAnuntImportant'))) {
       document.getElementById('anuntImportant').style.display='none';
    }
  }
}
<body onclick="hide()">

或者使用php会话,您需要在单击时调用ajax请求,然后在php中调用start_session并将$_SESSION['anuntImportant']设置为true,当您渲染元素时,您将设置style="display: none"

ajax.php

<?php
start_session();
$_SESSION['anuntImportant'] = true;
?>

yourpage.php

<?php 
start_session();
?>
  <body onclick="document.getElementById('anuntImportant').style.display='none'">
      <div id="anuntImportant" style="position: absolute; top:30%;left:40%; display:<?= $_SESSION['anuntImportant'] ? 'none' : 'block' ?>;overflow:visible; z-index:1000">
          <img src="image/data/program-sarbatori.jpg">
      </div>
  </body>