简体   繁体   English

每次重新加载页面时都会打开弹出式通讯表单

[英]Popup newsletter form opens every time when reload the page

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.提前致谢。

You can tackle this using local storage.您可以使用本地存储解决此问题。 MDN Documentation MDN 文档

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) (类似的事情可以用 cookie 来完成,但在这种特殊情况下,我认为本地存储适合您的用例)

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.请注意,未设置的本地存储项将返回null值。

In short every time the page loads execute getItem() and based on that value run the logic that you need.简而言之,每次页面加载时执行getItem()并基于该值运行您需要的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM