开发者

Set a jquery cookie on my fancybox onpage load

开发者 https://www.devze.com 2023-03-01 23:33 出处:网络
this is what is used 开发者_如何学Goto load fancybox on page load. However, I want this to be appeared on new visitors or people who visited the page 3 days ago.

this is what is used 开发者_如何学Goto 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'
        }
    );
});


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.


See Can jQuery read/write cookies to a browser?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消