-1

I want to add a automatic popup newsletter form to my static website(usinng google spreadsheet to collect mail). But when page reload every time popup shows up. I want something like if anyone press Subscribe or Not Now button popup will stop forever for their device. Is it possible?

I used this code. But When I reopen the browser Newsletter popup shows again.What I need to change here?

        $(document).ready(function () {

        if ($.cookie("dismiss") == null) {

            $('.modal').appendTo("body");
            function show_modal() {
                $('.modal').modal();
            }

            window.setTimeout(show_modal, 300);
        }

        $(".close").mouseenter(function () {
            document.cookie = "dismiss=true";
        });
    });

Thanks in advance.

1 Answers1

0

You can tackle this using local storage. MDN Documentation

With local storage you can save information that is not lost after a refresh. (Similar thing can be done with cookies, but in this particular case I think local storage fits your use case)

So you can try doing something like this:

// save item
localStorage.setItem("isUserSubscribed", true);

// get item
localStorage.getItem("isUserSubscribed");

Note that local storage items that are not set will return a null value.

In short every time the page loads execute getItem() and based on that value run the logic that you need.

Daniel Grima
  • 2,765
  • 7
  • 34
  • 58