jQuery - Set session with jQuery cookie plugin

0 votes
266 views
added Nov 16, 2018 in jQuery by LC Marshal Captain (25,790 points)
// Use the following code with the jquery dependency of: 
// https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js

$(window).load(function() {
  var stoAd = $(".sto-ads-content > div[id^='div-gpt-ad']");
    if ($.cookie('noSto')) $('.sto-ads').hide();
    else {
        if(stoAd.length > 0){
          $('.sto-ads .slide-close').on('click', function(){
            $(this).parent().parent().removeClass('in');
          });

          if ($('body').hasClass('front')) {
            setTimeout(function(){
              $('.sto-ads').addClass('in');
            },300);
            console.log('front');
          }
          else {
            // do not show the slide in the beginning
            setTimeout(function(){
              $('.sto-ads').addClass('in');
            },300);
            console.log('not-front');
          }
        }
        $.cookie('noSto', true);  
    }
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...