Automatic pop up window alert box or bootstarp modal alert box based on Timing setting
Automatic pop up window alert box or bootstarp modal alert box based on Timing setting
Hi guys am facing with the problem that I need a pop-up alert box window to raise automatically every day at morning 9:30 am and it should end at 11:30 am in the morning and again afternoon it should raise at 1:30 am to 2:30 add attendance of students.I tried but I have not able to set the timings according to our server timing .please see my code and help me guys and a huge appreciation for them.
<div class="modal fade" id="overlay"> <div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>Context here</p>
</div>
</div>
<script>$('#overlay').modal('show');setTimeout(function()
$('#overlay').modal('hide');, 5000);
moment.js
Hi @Bardia i need to set time and setout time interval based on date() object but still am trying its not coming yar
– Iswarya Swaminadhan
Aug 29 at 5:46
1 Answer
1
Since it's longer than a comment i have to post it here,
Let me explain it this way. you need few things before you can get your modal shown on specific time.
When you load a page and when your code reaches the line that you have Date()
function it will log that moment of time and that's where it stops.
Date()
And that's where you need some sort of live updating time so that you get live time. for this instance that's why i said you can use library like moment.js
.
moment.js
I'll give you both options here: (Vanilla)
function time()
var d = new Date();
var s = d.getSeconds();
var m = d.getMinutes();
var h = d.getHours();
span.textContent = h + ":" + m + ":" + s;
setInterval(time, 1000);
setInterval runs the time function every 1 seconds (1000 milliseconds).
to have your function act the way you want you can have an if statement on specific hour and then trigger your modal based on that. and hide it after certain time.
for your if condition you can write it like this :
if(d.getHours() == 9 && d.getMinutes() = 30)
//show modal
https://jsfiddle.net/xpvt214o/698686/
@Bradia let me try and tell the results what else.
– Iswarya Swaminadhan
Aug 29 at 6:10
hi @Bradia i tried this code still not working see <script> function time() var d = new Date(); var s = d.getSeconds(); var m = d.getMinutes(); var h = d.getHours(); span.textContent = h + ":" + m + ":" + s; setInterval(time, 1000); if(d.getHours() == 12 && d.getMinutes() = 10) $('#overlay').modal('show'); setTimeout(function() $('#overlay').modal('hide'); , 5000); </script>
– Iswarya Swaminadhan
Aug 29 at 6:42
hi @Bardia i tried another method also here still not working what can i do see here the script <script> function time() var d = new Date(); var s = d.getSeconds(); var m = d.getMinutes(); var h = d.getHours(); span.textContent = h + ":" + m + ":" + s; setInterval(time, 1000); if(d.getHours() == 12 && d.getMinutes() = 18) $('#overlay').modal('show'); setTimeout(function() $('#overlay').modal('hide'); , 5000); </script>
– Iswarya Swaminadhan
Aug 29 at 7:03
have a look at this jsfiddle.net/xpvt214o/698683
– Bardia
Aug 29 at 7:06
the problem was that your if condition was out of the loop and it was not being triggered .
– Bardia
Aug 29 at 7:06
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
one thing that you need to keep in mind that, your client is unaware of the state/time of the server once is being loaded. if you constantly want to check against server time you need to make multiple calls to the server to check. or you can use js libraries like
moment.js
to do it on your client side– Bardia
Aug 29 at 5:40