Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
How to set expiry date on pop-up in javascript

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');
    });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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');
}
about 4 years ago · Juan Pablo Isaza Report

0

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');
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!