0

试图检查 cookie 是否存在。如果没有,则启动基础显示模式。单击模式上的按钮时,会设置一个新的 cookie,以便下次加载页面时不会加载模式。

我设法设置了 cookie,但是我的检查似乎不起作用,因为即使 cookie 在我的浏览器历史记录中,我的模式框也会出现。

$(document).ready(function () {

    if ($.cookie('ageVerification') == undefined || $.cookie('ageVerification') == null || $.cookie('ageVerification') != 'Verification that user is over the legal drinking age in your country') {

        // Reveal modal
        $("#myModal").reveal();

        // Set Cookie on click 
        var ageVerification = document.getElementById('ageVerification');

        ageVerification.addEventListener('click', function (event) {
            $.cookie('ageVerification', 'Verification that user is over the legal drinking age in there country', {
                expires: 10, //expires in 10 days

                path: '/', //The value of the path attribute of the cookie 
                //(default: path of page that created the cookie).

                domain: 'becketts.knibbshost.co.uk', //The value of the domain attribute of the cookie
                //(default: domain of page that created the cookie).

                secure: true //If set to true the secure attribute of the cookie
                //will be set and the cookie transmission will
                //require a secure protocol (defaults to false).
            });
            $('#myModal').hideModal()
        });
    }
});
4

1 回答 1

-1

Fixed the extra settings on the set of my cookie, were not working.

answer needs the following scripts to run:

$(document).ready(function () {

if ($.cookie('ageVerification') == undefined || $.cookie('ageVerification') == null) {

    // Reveal modal
    $("#myModal").reveal();

    // Set Cookie on click 
    var ageVerificationBtn = document.getElementById('ageVerification');

    ageVerificationBtn.addEventListener('click', function (event) {
        $.cookie('ageVerification', 'Verification that user is over the legal drinking age in there country', {
            expires: 10, //expires in 10 days
        });
        $('#myModal').hideModal()
    });
}

});

于 2014-06-24T13:40:19.990 回答