简体   繁体   English

如何在第二次访问WordPress页面时隐藏引导程序模式

[英]how to hide bootstrap modal on second visit of a wordpress page

i'm working on a page in wordpress with the Bootstrap theme. 我正在以Bootstrap为主题的wordpress中的页面。 there is a modal window on page load having a registration form on it.user can not see the content without filing the form.my problem is that whenevr user comes back to that page it shows the modal window,and i want to restrict that to once for a user.How can i achieve that. 页面加载上有一个模态窗口,上面有一个注册表单。用户无法提交表单就看不到内容。我的问题是,当evr用户返回该页面时,它会显示模态窗口,我想将其限制为一次给用户。我怎么能做到这一点。

Here is my Js for modal: 这是我的模态Js:

<script type="text/javascript">
jQuery(document).ready(function($) {
    $('#DownloadSignup').modal('show');
});
</script>

Here is what i have tried but its not working: 这是我尝试过的方法,但无法正常工作:

<script>
jQuery(document).ready(function($) {
    var isshow = localStorage.getItem('status');
  // alert(isshow);
    if (isshow == null) {
        localStorage.setItem('isshow', 1);

        // Show popup here
        $('#DownloadSignup').modal('show');
    } else if(isshow != null) {
       $('#DownloadSignup').modal('hide');
    }
});
</script>

You need to use cache or sessions for this. 您需要为此使用缓存会话

If want it for non-logged in user also, you should use cache. 如果还希望非登录用户使用它,则应使用缓存。 The cache need to be check if they exist on the system everytime the site is visited, if they are already set, don't show the modal. 每次访问站点时,都需要检查缓存是否存在于系统中(如果已设置),则不要显示模式。 These will be set on the first visit, so that for every visit after that it will be already there thus hiding the modal. 这些将在第一次访问时设置,以便在此之后的每次访问都已经存在,从而隐藏了模式。

If you need it with logged in user, you should use session, following same logic as above. 如果需要登录用户使用它,则应使用会话,遵循与上述相同的逻辑。 Setting a value in session and checking if it exists before displaying the modal. 在会话中设置一个值,并在显示模式之前检查它是否存在。

Change this 改变这个

localStorage.setItem('isshow', 1);

to

localStorage.setItem('status', 'shown');

Use this code in your page, I hope it will help you. 在您的页面中使用此代码,希望对您有所帮助。

<script>
    if (!localStorage['someName']) {
        localStorage['someName'] = 'yes';
        myFunction();
    }
</script>

I guess you are not checking it correctly if you checking for if local-storage is set or no then you have to check its type and value like below... 我想如果您检查是否设置了本地存储,则您没有正确检查它,那么您必须检查其类型和值,如下所示...

var = localStorage.getItem('status');
if (localStorage.getItem("isshow") === null) {
   //...
} 

Have you tried using Jquery Cookies. 您是否尝试过使用jQuery Cookies。 You can use this lib https://github.com/carhartl/jquery-cookie 您可以使用此库https://github.com/carhartl/jquery-cookie

$.cookie("Show", 1, {
   expires : 1,           //expires in 1 day

   path    : '/',          //The value of the path attribute of the cookie 
                           //(default: path of page that created the cookie).

   domain  : 'yourdomain.com',  //The value of the domain attribute of the cookie
                           //(default: domain of page that created the cookie).

   secure  : true          //If set to true the secure attribute of the cookie
                           //will be set and the cookie transmission will
                           //require a secure protocol (defaults to false).
});

If you are not interested in JQuery look at this other answer on how to set using native JS. 如果您对JQuery不感兴趣,请查看有关如何使用本机JS进行设置的其他答案。 https://stackoverflow.com/a/1460174/1411055 https://stackoverflow.com/a/1460174/1411055

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

相关问题 如果用户单击“返回”,如何在上一页中隐藏引导程序模式? - How to hide a bootstrap modal on the previous page if user comes in clicking BACK? 如何在我的 web 页面中隐藏或显示引导模式? - How can I hide or show a bootstrap modal in my web page? Vue Bootstrap - 当第二个模态打开时隐藏第一个模态 - Vue Bootstrap - Hide first Modal when the second modal is open 如何通过单击第一页中的按钮激活 Bootstrap 4 模态,将您重定向到激活模态的第二页? - How to activate Bootstrap 4 modal by clicking a button in the first page, that redirects you to a second page with modal activated? Bootstrap如何隐藏模态? - How does Bootstrap hide the modal? 如何使用 javascript 隐藏 Bootstrap 模式? - How to hide Bootstrap modal with javascript? 如果我第二次访问应用程序,如何重定向到第二个页面 - How to redirect to a second page if I visit the application second time Bootstrap Modal 在第二页的 DataTable 中不起作用 - Bootstrap Modal Not working in DataTable From Second page Javascript显示隐藏输入在第二次加载引导模态时不起作用 - Javascript Show Hide input not working the second time bootstrap modal is loaded 如何在页面的第二次访问时激活javascript? - How to make a javascript active just on the second visit on the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM