Saturday, June 6, 2020

One time popup using cookie

<script type="text/javascript">

var cookie = document.cookie;

if (cookie.indexOf('visited=', 0) == -1) {

    var expiration = new Date();

    expiration.setDate(expiration.getDate()+1);

    document.cookie = 'visited=1;expires=' + expiration + ';path=/';


    var element = document.getElementById('myModal');

    element.style.display = 'block';

}

</script>

<?php if (!isset($_COOKIE['visited'])) {

    @setcookie('visited', true, time() + 3600 * 24); // Save a cookie for 1 day

    echo '<div class="load-img-box modal show" id="myModal"style="display: none;" role="dialog">

    <div class="vertical-alignment-helper">

     <div class="modal-dialog vertical-align-center">

      <div class="modal-content">

        <div class="modal-body">

        <img src="images/GST-Margin.jpg" alt="" />

        </div>

        <div class="modal-footer">

          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

        </div>

      </div>

    </div>

    </div>

  </div>';

}?>

No comments:

Post a Comment