Age verification popup with fancybox


Below code is responsible for open a Fancybox on page load and verify visitor’s age. If visitors age was 18 then cookies is set for next access without verification popup, — if not then a warning message will display.

    jQuery(document).ready(function() {
//ceheck cookies is set or not
    checkCookie();
    
});

function checkCookie()
{
    var age = getCookie("age");

    if (parseInt(age) <= 17 || age == null || age == "")
    {
        jQuery("#popuppage").fancybox({
            afterLoad: function() {
                this.content = this.content.html();
            },
            closeBtn: false,
            helpers: {
                overlay: {
                    closeClick: false,
                    locked: true,
                    css: {
                        'background': 'rgba(148, 212, 212, .9)'
                    }
                }
            }
        }).trigger('click');
    }

}

//set cookies value
function setCookie(value)
{
    c_name = "age";
    exdays = 365;

    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
    window.parent.jQuery.fancybox.close(); // close fancybox 
}

//get value of cookies
function getCookie(c_name)
{
    var c_value = document.cookie;
    var c_start = c_value.indexOf(" " + c_name + "=");
    if (c_start == -1)
    {
        c_start = c_value.indexOf(c_name + "=");
    }
    if (c_start == -1)
    {
        c_value = null;
    }
    else
    {
        c_start = c_value.indexOf("=", c_start) + 1;
        var c_end = c_value.indexOf(";", c_start);
        if (c_end == -1)
        {
            c_end = c_value.length;
        }
        c_value = unescape(c_value.substring(c_start, c_end));
    }
    return c_value;
}

function WarringMsg()
{
    alert("Our product is not appropriates for individuals under 18.");
    return false;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s