Problem with a modal

Asked

Viewed 504 times

4

inserir a descrição da imagem aqui

Well I have a problem with this modal, it opens so q enters the index.php, but if I change the page by ex for doubts.php and click to return to index.php Alert appears again, has to configure to Alert only appear once and only appear dnv if the person closes the tab?

code :

<script>
function fechaAviso(){
    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>
  • Puts the script that opens the modal.

  • @Leandroangelo already put bro.

  • there is what closes...

  • That’s all there is in the script

  • It appears when you load the page .

  • It’s not a modal button .

Show 1 more comment

2 answers

1

Create a session that expires when the browser is closed

Place this PHP at the beginning of your page

<?php
session_start();
?>

Preferably put the code below before the body closing tag on 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>
<script src="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 -->
  • I put this section before html, and create a div no body?

  • thanks @leo .

  • I tried to add this code before html and create a div right after body appeared but all weird, and it doesn’t work when clicking it and go to another page and come back again appears.

1


You can create a $_SESSION to know if modal has already been opened. When the user leaves the website browser, SESSION expires.

You can do so by showing the modal only if the SESSION has not been set:

<?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 the use of SESSION, don’t forget to put it at the top of the page (before the tag <html>):

<?php
session_start();
?>

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

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

  • The code is before the html tag?

  • @Felipe only the session_start();. The modal is in the same place as the modal

  • but this would solve if the person changes to doubts.php and on the page doubts.php clicking on index.php will appear dnv?

  • @Felipe No. It will only appear again if the Session expires

  • mt thanks bro !

  • <?php if(!isset($_SESSION["modal"]){ $_SESSION["modal"] = true; ? > only this part here is before html

  • the modal div gets after that is not it?

  • I got a little confused because of this last php q vc put

  • @Felipe this last php eh to start Session on the page, soh this

  • so this php q is separated I put under the div or at the end of the page?

  • When I first saw this question, it had no PHP tag and no answers. But tell me, does the session expire when the user leaves the site or closes the browser? I think I’m seeing things kkk

  • @Leocaracciolo True. Correct is when you close the browser.

  • Entonces, make the proper correction in response under penalty of winning a -1

  • @Leocaracciolo I’ve changed. I work a lot with Session, at the time of writing wrong. Thanks.

  • I tried to add this code before html and create a div right after body appeared but all weird, and it doesn’t work when clicking it and go to another page and come back again appears.

Show 11 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.