简体   繁体   中英

Disable Fancybox Pop-Up With Cookies

I have a Fancybox set on a delay to pop up on any page of my Wordpress, I'm looking to have it become disabled after a user submits something in the provided input or have it not show up for a given amount of time if the user clicks on the bypass link. I've tried a few scripts found around this site but nothing seemed to work, here's what I currently have set in place.

function openFancybox() {
        setTimeout( function() {$('.pop').trigger('click'); },20000);
    }
    $(document).ready(function() {
        var visited = $.cookie('visited');
        if (visited == 'yes') {
            return false;
        } else {
            openFancybox();
        }
        $.cookie('visited', 'yes', { expires: 7 });
        $('.pop').fancybox();
    });

Please try the below to see if that helps.

openFancybox = function{
   setTimeout( function() {$('.pop').trigger('click'); },20000);
}

$(document).ready(function() {
   //Declare your cookie.
   $.cookie('visited','no', { expires: 7 });

   //Test to see if your cookie equals 'no', if true then run the fancy box.
   if ($.cookie('visited') == 'no') {
           openFancybox();
   }

   //Your Input or click to stop the fancy box
   $('#StopFancyBox').on('click',function(){
       $.cookie('visited', 'yes');
   });
});

As @Brad mentioned you can use the web developer tools to test to see what your cookie value is at stages. Simply go to the web.console and call back $.cookie('visited')

ERRORS

jquery.cookie.jsGET http://www.coreytegeler.com/bolivares/wp-content/themes/max-magazine/source/cookies/jquery.cookie.js 404 (Not Found)

The above seems to be because the jquery.cookie.js file is not referencing the right location.

/bolivares/:72SyntaxError: Expected token '('

The above is actually my fault :) sorry. When declaring the function openFancybox i missed off the (). So it should be openFancybox = function(){ .

jquery-plugins.min.js:13TypeError: 'undefined' is not an object (evaluating 'e.browser.msie')
superfish.js:123TypeError: 'undefined' is not a function (evaluating 'jQuery('ul.nav').superfish()')
woocommerce.min.js:1TypeError: 'undefined' is not a function (evaluating 'e(".plus").live')

The above are conflicts with the plugins jquery-plugins.min.js, superfish.js and woocommerce.min.js respectively. I'm sorry I can't give much guidance on these.

/bolivares/:259ReferenceError: Can't find variable: myLoop

You're calling back myLoop(i) on line 259 on your main html page. But searching through all of your scripts, this isn't declared anywhere.

Yes you can edit it perfectly all you have to do is create a settimeout value so that the fancybox pops out after some time and then write the program like this

    <script type="text/javascript">
function openFancybox() {
    setTimeout( function() {$('#fancybox-manual-b').trigger('click'); },5000);
}
$(document).ready(function() {
    var visited = $.cookie('visited');
    $.cookie('visited', 'yes', { expires: 7 }); /*write this first*/
    if (visited == 'yes') {
        function callback(a){
                return function(){
                alert("Hello " + a);
                                    }
                                    }
                var a = "world";
                setTimeout(callback(a), 2000); /*let the page load first*/
                a = "subscriber";
    } else {
        openFancybox();
    }
    $('#fancybox-manual-b').fancybox();
});
</script>

If you want you can change the (I wrote this to check if the cookie is working properly or not)

if (visited == 'yes') {
        function callback(a){
                return function(){
                alert("Hello " + a);
                                    }
                                    }
                var a = "world";
                setTimeout(callback(a), 2000);
                a = "idiotteen";
    }

to

if (visited == 'yes') {
return false;
}

Let me know if this helped you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM