Set a jQuery cookie to show popup only once

后端 未结 6 550
野性不改
野性不改 2020-12-14 02:36

I\'m an absolute newbie in jQuery. I\'m learning, but there is a Christmas message that I need to get up and running within no time.

I\'ve included these in the head

6条回答
  •  忘掉有多难
    2020-12-14 03:27

    First include the jquery library.

    After include the below script for cookies in jquery.

    
    

    Now put the below code into the footer :

    $(document).ready(function() {
           // initially popup is hidden:
            $('#stay-in-toch.popup-outer').hide();
            // Check for the "whenToShowDialog" cookie, if not found then show the dialog and save the cookie.
            // The cookie will expire and every 2 days and the dialog will show again.
            if ($.cookie('whenToShowDialog') == null) {
                // Create expiring cookie, 2 days from now:
                $.cookie('whenToShowDialog', 'yes', { expires: 2, path: '/' });
    
                // Show dialog
                 $('#stay-in-toch.popup-outer').show();       
            }
        });
    

提交回复
热议问题