I am calling a ‘modal pop’ (#myModal) on ‘window on load’. As expected, its displaying every time when the user navigating from one page to another or during page refresh
and its really annoying. Is there any other way to ‘display pop up only once’ when the user login into the system ?
var currentTime = new Date();
$(document).ready(function() {
var date = new Date();
switch (date.getDay()){
case 0: myPlay();
break;
case 3: myPlay();
break;
case 4: myPlay();
break;
case 5: myPlay();
break;
case 6: myPlay();
break;
}
});
function myPlay(){
$(window).on('load', function(){
$('#myModal').modal('show');
});
var datetime = document.getElementById('myModalLabel');
datetime.innerHTML = currentTime;
}
I have tried the localStorage. It will display once when the user login, but once the user logout from the system and login back the pop up will not display again. Only way is clearing the browser cache and try login again, then it will start displaying the pop up. Is this is expected behaviour with localStorage ?
If you want it to display when the user logs back in, either clear the value from localStorage when they logoout, or use sessionStorgare, which gets cleared when the page session ends.