Control of the appearance of modal

Asked

Viewed 258 times

1

I created a modal, that when clicking on a click it asks if the person wants to register the email to receive more information. And this modal is on more than one link throughout the site. Could I control the appearance of it? Like if the person has seen this modal, even if they have not put the email (not to be boring), it only appears once?

Thanks in advance.

  • you want it to appear once per visit or once when accessing the site? for both you can create sessions on the customer’s machine, or cookies.

  • I want to visit!

2 answers

2

You can do it this way:

Janela Modal

<!-- 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>

Don’t forget that in your main file, it must contain session_start() to start Sesssion.

  • That day I asked a question about the attribute aria and read and did not understand, can give some hint what exactly it does in your code ?

  • 1

    The ARIA tags serve to better explain the semantics of your HTML for accessibility technologies, such as screen readers that scan a web app and turn this information into a user-friendly description for visually impaired people. Take a look at this answer: http://stackoverflow.com/questions/3474099/what-is-html5-aria

  • Good morning! I tried to do, but here in mine it still shows the modal. I signed in but it didn’t work no.

  • Post your code, like you tried to do.

  • Follow the code below.

0

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

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

Then I took the code from Jquery 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>

Browser other questions tagged

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