Code Tricks

Show popup once

Set a cookie so the banner only shows once.

Created by

Code & Wander

See resource

Code

<script>
var Webflow = Webflow || [];
Webflow.push(function() {

  // Load cookie library
  $.getScript("https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js", function() {

    // If cookie found (already shown)
    if(Cookies.get('promotion') !== undefined) {

      // Hide cookie notice (change jQuery selector to match your own)
      $('.banner').remove();
    }
    else {$('.banner').show();}

    // On close
    $('.banner-close-button').click(function() {
      // Calculate when you want to display the notice again (change 15 to number of minutes you want)
      var expireTime = new Date(new Date().getTime() + 60000 * 60 * 24 * 60);
      // Set this cookie
      Cookies.set('promotion', 'shown', { expires: expireTime });
    });
    
     // On link/button click
    $('.banner-link').click(function() {
      // Calculate when you want to display the notice again (change 15 to number of minutes you want)
      var expireTime = new Date(new Date().getTime() + 60000 * 60 * 24 * 60);
      // Set this cookie
      Cookies.set('promotion', 'shown', { expires: expireTime });
    });
  });

});
</script>
Copied!

Tutorial

Steps & Description

Tips & Notes

Related resources

No items found.