简体   繁体   中英

How to set Cookie on Fancybox Close Button

I have the script below that works, but it activates the cookie on load. How do I get the cookie to activate only when the close button is clicked? On the "OnLoad.html" page I have a close button and a link button. I only want the cookie to load when the close button is clicked.

I did try the suggestion in the question titled "Setting cookie on click fancybox close button" and it did not work at all.

Thank you.

$(function() {
    if ($.cookie('test')) {
    } 
    else {     
       // set cookie to expire in x days
       $.cookie('test', 'true', { expires: 50 * 365 });
        $.fancybox( {
            href : 'example.com/OnLoad.html',
            type: 'ajax',
            helpers:  {
                overlay : null
            },
            keys : {
                close  : null
            },   
            closeBtn    : false,
       });
    }
});

Jquery

$("<YOUR-SELECTOR>").fancybox({
  onClosed: function() {
   $.cookie('test', 'true', { expires: 50*365});
  })
});

then create the cookie on session.php

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