0

I have initialized a popup

var popup = modal(options, $('#notification-modal'));
    $("#notification-link").on('click', function () {
        $("#notification-modal").modal("openModal");
    });

    $(document).ready(function () {
        $("#notification-link").trigger("click");
    });

But the above popup triggers on every refresh. I want the popup to load once once the site is called or closing and opening the browser again to the page (based on session expire).

1 Answer 1

0

Based on your code make changes as per below and check

 var popupCookie = $.cookie('popupNewsletterOff');
 if(!popupCookie || popupCookie == 'undefined'){
    var popup = modal(options, $('#notification-modal'));
    $("#notification-link").on('click', function () {
        $("#notification-modal").modal("openModal");
        $.cookie('popupNewsletterOff', true);
    });

    $(document).ready(function () {
        $("#notification-link").trigger("click");           
    });
 }
2
  • the above code is not working and popup has to work based upon session storage. The popup has to open if the user has closed the browser and opened again. In cookies we couldn't achieve it.
    – Haerriz
    Commented Dec 1, 2020 at 6:26
  • if we don't pass expiry parameter then it works as a session
    – Dharmesh
    Commented Dec 1, 2020 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.