Problem with a modal

4

Well,Ihaveaproblemwiththismodal,itopensassoonasIentertheindex.php,butincaseIchangethepagetoextoduvidas.phpandclicktogobacktoindex.phpthealertappearsagain,forthealertonlyappearsonceandonlyappearsdnvifthepersonclosethetab?

code:

<script>functionfechaAviso(){document.querySelector("#tela").style.display = "none";
    // jquery abaixo
    //$("#tela").hide();
}
</script>

html:

    <div id="tela">

   <div id="aviso">
      <h2>ATENÇÃO</h2>
      <p>ESTE SITE (ELOJOBMAX.COM.BR) NÃO POSSUI QUALQUER TIPO DE VÍNCULO E/OU AGREGAÇÃO COM A RIOT GAMES E SUAS MARCAS, BEM COMO SEUS RESPECTIVOS WEBSITES.</p>
        <input class="btleave"type="button" value="SAIR DO SITE" onclick="fechaAviso()" />
      <input class="btjoin" type="button" value="ESTOU CIENTE E CONCORDO" onclick="fechaAviso()" />
   </div>
</div>
    
asked by anonymous 08.01.2018 / 21:04

2 answers

1

You can create $_SESSION to see if modal has already been opened. When the user exits the site browser , SESSION expires.

You can do this by showing the modal only if SESSION has not been defined:

<?php
if(!isset($_SESSION["modal"])){
   $_SESSION["modal"] = true;
?>
<div id="tela">
   <div id="aviso">
      <h2>ATENÇÃO</h2>
      <p>ESTE SITE (ELOJOBMAX.COM.BR) NÃO POSSUI QUALQUER TIPO DE VÍNCULO E/OU AGREGAÇÃO COM A RIOT GAMES E SUAS MARCAS, BEM COMO SEUS RESPECTIVOS WEBSITES.</p>
        <input class="btleave"type="button" value="SAIR DO SITE" onclick="fechaAviso()" />
      <input class="btjoin" type="button" value="ESTOU CIENTE E CONCORDO" onclick="fechaAviso()" />
   </div>
</div>
<?php
}
?>

To enable SESSION, do not forget to put it at the top of the page (before the <html> tag):

<?php
session_start();
?>

Why session_start(); at the top of the page?

Because in the future you may have to work with SESSION in <header> , and then SESSION will be enabled in the entire document.

    
09.01.2018 / 00:43
1

Create a session that expires when the browser is closed

  

Place this PHP at the top of your page

<?php
session_start();
?>
  

Preferably put the code below before the body closing tag of your page

<!-- inicio modal -->
<?php
 if ((!isset($_SESSION['visitada']))&&(empty($_SESSION['visitada']))){
?>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
        <div id="tela">
          <div id="aviso">
            <h2>ATENÇÃO</h2>
            <p>ESTE SITE (ELOJOBMAX.COM.BR) NÃO POSSUI QUALQUER TIPO DE VÍNCULO E/OU AGREGAÇÃO COM A RIOT GAMES E SUAS MARCAS, BEM COMO SEUS RESPECTIVOS WEBSITES.</p>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger waves-effect waves-light" data-dismiss="modal">SAIR DO SITE</button>
        <button type="button" class="btn btn-success waves-effect waves-light" data-dismiss="modal">ESTOU CIENTE E CONCORDO</button>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript">
    $("#myModal").modal('show');
</script>';

<?php 
    $_SESSION['visitada'] = "visitada";         
}
?>
<!-- fim modal -->
    
09.01.2018 / 01:55