1

this is what is used to load fancybox on page load. However, I want this to be appeared on new visitors or people who visited the page 3 days ago.

I guess with a jQuery cookie but I don't know how.

jQuery(document).ready(function() {
    $.fancybox(
        '<h2>Hi!</h2><p>Lorem ipsum dolor</p>',
        {
                'autoDimensions'    : false,
            'width'                 : 350,
            'height'                : 'auto',
            'transitionIn'      : 'none',
            'transitionOut'     : 'none'
        }
    );
});
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

3 Answers3

0

I have read this and tried to incorporate this to my website but its not working.

In my 'theme.liquid'

Under ''

I have this:

<script src="jquery.cookie.js"></script>

In my 'jquery.cookies.js'

I have:

$(function() {
    if ($.cookie('mycookie')) {

    } else {
        $.fancybox(
            '<script src="//setup.shopapps.io/social-login/script/snookieshop.js?width=300&height=330"></script>'
,
            {
                'autoDimensions'    : true,
                'width'             : 350,
                'height'            : 'auto',
                'transitionIn'      : 'none',
                'transitionOut'     : 'none'
            }
        );
    }
});

$.cookie('mycookie', 'true', { expires: 1});

The reason why I have this Script is because I am using a app from Shopify and this is the line of code they gave me for a sign up with social media.

<script src="//setup.shopapps.io/social-login/script/snookieshop.js?width=300&height=330"></script>

The purpose of doing this is because I want the pop-up screen to appear on the homepage whenever a customer comes in and visits.

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
0

See Can jQuery read/write cookies to a browser?

Community
  • 1
  • 1
Thomas Shields
  • 8,874
  • 5
  • 42
  • 77
0

In your <head> add <script src="jquery.cookie.js"></script>, then:

$(function() {
    if ($.cookie('mycookie')) {
        // it hasn't been three days yet
    } else {
        $.fancybox(
            '<h2>Hi!</h2><p>Lorem ipsum dolor</p>',
            {
                'autoDimensions'    : false,
                'width'             : 350,
                'height'            : 'auto',
                'transitionIn'      : 'none',
                'transitionOut'     : 'none'
            }
        );
    }
});

// set cookie to expire in 3 days
$.cookie('mycookie', 'true', { expires: 3});

This uses the cookie plugin.

Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197