简体   繁体   English

如何在Fancybox关闭按钮上设置Cookie

[英]How to set Cookie on Fancybox Close Button

I have the script below that works, but it activates the cookie on load. 我有下面的脚本可以工作,但是它会在加载时激活cookie。 How do I get the cookie to activate only when the close button is clicked? 如何仅在单击关闭按钮时激活cookie? On the "OnLoad.html" page I have a close button and a link button. 在“ OnLoad.html”页面上,我有一个关闭按钮和一个链接按钮。 I only want the cookie to load when the close button is clicked. 我只希望单击关闭按钮时加载cookie。

I did try the suggestion in the question titled "Setting cookie on click fancybox close button" and it did not work at all. 我确实尝试了题为“在单击fancybox关闭按钮时设置cookie”的问题中的建议,但它根本没有起作用。

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 jQuery的

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

then create the cookie on session.php 然后在session.php上创建cookie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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