www.webdeveloper.com
Results 1 to 2 of 2

Thread: Pop up that displays only if cookie not present

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Posts
    2

    Pop up that displays only if cookie not present

    Hi Guys first time on the forum so please forgive my ignorance.
    I've put togethere a form with a script that creates a cookie when users select various options. The form is going to appear in a popup (i'm using colorbox jquery for this). I can get the popup form to appear when people visit my target page but what I can't seem to get right is a script that first checks if my cookie is present, and if it isn't then fire up my popup.
    Here is what i have so far and would greatly appreciate any guidance you can offer me.

    window.onload = function(){

    if(document.cookie)
    {
    index = document.cookie.indexOf(Survey);
    if (index != -1)
    {
    $(document).ready(function() {
    $.fn.colorbox({href:'survey.htm', open:true});
    });
    }
    }
    }

  2. #2
    Join Date
    Nov 2009
    Posts
    2
    Finally brute force and ignorance have prevailed!

    I found another script at; http://codingforums.com/showthread.php?t=13708 and amaneded it.

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }

    function loadornot(){
    if (get_cookie('Survey')==''){
    $(document).ready(function() {
    $.fn.colorbox({href:'survey.htm', open:true});
    });
    }
    }

    loadornot()

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles