Show modal at a certain time and close at a default time

0

I have a modal and I would like it to appear and disappear at a specific time, the idea is to notify the client that the site is closed at a certain time.

For now I have this, but it did not work.

<script>
window.onload = function () {
  DisplayCurrentTime();
};

function DisplayCurrentTime() {
 var d = new Date();
 var hour = d.getHours();
 var min = d.getMinutes();

  if(hour <= 22 && min === 0){
    $("#horadl").modal("show");
  }else{
    if(hour <= 7 && min === 0){
      $("#horadl").modal("hide");
    }
  }
}
</script>


<div class="modal fade" id="horadl" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"><!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
<h1 style="text-align: center;">Oops!</h1>
</div>
<div class="modal-body" style="text-align: justify;">
<br /><br /> En este momento nos encontramos descansando, esperamos contar con ustedes mañana.
<br /> Nuestro horario de atención es:<br />7:00 AM - 10:00 PM</div>
<div class="modal-footer"><a href="#" class="btn btn-success">Aceptar</a></div>
</div>
</div>
</div>

Please some documentation, suggestions or help. Thanks.

    
asked by SpartanDark 29.11.2018 в 17:08
source

1 answer

0

Correcting a bit that logic that you pose can achieve what you want, always keeping in mind that it will take the time of the user's computer:

if(hour >= 7 && hour <= 22){
    $("#horadl").modal("show");
  }else{ 
    $("#horadl").modal("hide");
  }

The problem of the solution that you implemented is that it is TRUE only if it gives the time in point if it is not the hour in point the conditional will not be executed, that is to say at 7:00 it is TRUE, but at 7 : 01 is FALSE instead as I wrote it now only takes into account the time, not the minutes, if the time is greater than or equal to 7 AND less or equal to 22 will launch the modal.

I hope this solves your problem.

    
answered by 29.11.2018 / 17:39
source