每次会话/访问时弹出一次oncer [英] Pop up oncer per session/ visit

查看:58
本文介绍了每次会话/访问时弹出一次oncer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jQuery添加一个弹出窗口,该弹出窗口在每次会话/访问时都会出现一次.

I want to use jQuery to add a pop up that appears once per session/visit.

我尝试过:

jQuery(document).ready(function($) {  
  setTimeout(function() {
    if (!sessionStorage.previouslyVisited) {
      $('#exampleModalTextLink').modal('show');
      sessionStorage.previouslyVisited = true;
    }
  }
});

在此步骤中,以便每个会话一次出现该弹出窗口(我在引导程序4上做到了)

in this one, so that the pop up appear once per session (I made it on bootstrap 4)

$(window).load(function(){
  setTimeout(function() {
    $('#exampleModalTextLink').modal('hide');
  }, 15000);
  setTimeout(function(){
    $('#exampleModalTextLink').modal('show');
  }, 2000);
});

推荐答案

您需要通过以下方式设置和获取会话变量

You need to set and get the session variables the following way

jQuery(document).ready(function () {
    // Get saved data from sessionStorage
    var visited = sessionStorage.getItem('visited');

    setTimeout(function () {
        if (visited !== true) {
            $('#exampleModalTextLink').modal('show');
            sessionStorage.setItem('visited', true); // Save data to sessionStorage
        } 
    }, 500);

});

如果falsenull,它将检查现有值,然后将调用modal,否则不会,如果使用setTimeout >.请参见文档

this will check for an existing value if false or null then it will call the modal otherwise won't, I don't know why are you using setTimeout if you are using the document.ready. See here for documentation

这篇关于每次会话/访问时弹出一次oncer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆