I have a modal which appears once per user , and I am using local storage to achieve this. However, I am now trying to make it so that after a certain date ( 1/03/2022) to not appear at all. Here is my logic at the moment:
$(document).ready(function () {
var key = 'hadModal',
hadModal = localStorage.getItem(key);
if (!hadModal) {
$('#PIAModal').modal('show');
}
$(".btn").click(function () {
localStorage.setItem(key, true);
$("#PIAModal").modal('hide');
});
$(".modal").click(function () {
localStorage.setItem(key, true);
$("#PIAModal").modal('hide');
});
You can make a function to check if it's the due date and pass it to the conditional
function isBeforeDate() {
let today = new Date();
const endDate = new Date("2022-03-01");
if (today < endDate) {
return true
} else {
return false
}
}
if (!hadModal && isBeforeDate()) {
$('#PIAModal').modal('show');
}
You can create Date objects in Javascript and compare them.
var now = new Date();
var end = new Date("2022-03-01");
if (now < end) {
$('#PIAModal').modal('show');
}