Control of modal appearance

1

I created a modal, which when clicking a click it asks if the person wants to register the email to receive more information. And this mod is in more of a link throughout the site. How could I control the appearance of it? Type if the person has already seen this modal, even if you have not put the email (so as not to be boring), it only appears once?

Thank you in advance.

    
asked by anonymous 27.10.2016 / 21:56

2 answers

2

You can do this as follows:

Modal Window

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<script>
    jQuery(document).ready(function(){
        <?php if(!$_SESSION['modal_aberta']){ ?>
        $("#myModal").show(); // se ainda não tiver aberto a modal, exibe
        <?php
            $_SESSION['modal_aberta'] = '1'; // seta que já foi aberta a modal.
        ?>
        <?php } ?>
    });
</script>

Do not forget that your main file should contain session_start () to start the session.

    
27.10.2016 / 22:11
0

Well I started the session and set the variable to 0.

<?php session_start(); 
$_SESSION['modal_aberta'] = 0; ?>

Then I got the JQuery code and did so

  <script>
jQuery(document).ready(function(){
    <?php if(!$_SESSION['modal_aberta'] == 0){ ?>
    $("#myModal3").show(); // se ainda não tiver aberto a modal, exibe
    <?php
        $_SESSION['modal_aberta'] = 1; // seta que já foi aberta a modal.
    }else{ ?>
      $("#myModal3").hide();
    <?php } ?>
}); </script>
    
28.10.2016 / 15:34