Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using setTimeout with cookies for use in survey

    Hi
    Im trying to implement an online survey (via surveymonkey) on my site, and i want users to get a chance to actually look at the site, before the popup containing the survey appears. But im having some diffulties getting it to work. i had it working with the delay before setting up cookies, but now its not responding to my setTime. I probably just overlooked something obvious, but im stuck and frustrated now. So, any help would be appriciated.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Popup Survey</title>
    <script language="javascript">
    var expDays = 60;
    
    var page = "popup_link.html";
    var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
    function GetCookie (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
      }
      return null;
    }
    
    function SetCookie (name, value) {
      var argv = SetCookie.arguments;
      var argc = SetCookie.arguments.length;
      var expires = (argc > 2) ? argv[2] : null;
      var path = (argc > 3) ? argv[3] : null;
      var domain = (argc > 4) ? argv[4] : null;
      var secure = (argc > 5) ? argv[5] : false;
      document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    }
    function DeleteCookie (name) {
      var exp = new Date();
      exp.setTime (exp.getTime() - 1);
      var cval = GetCookie (name);
      document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
    
    function amt(){
      var count = GetCookie('count')
      if(count == null) {
        SetCookie('count','1')
        return 1
      } else {
        var newcount = parseInt(count) + 1;
        DeleteCookie('count')
        SetCookie('count',newcount,exp)
        return count
      }
    }
    
    function getCookieVal(offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
      endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }
    function checkCount() {
      var count = GetCookie('count');
      if (count == null) {
        count=1;
        SetCookie('count', count, exp);
        window.open(page, "", windowprops);
      } else {
        count++;
        SetCookie('count', count, exp);
      }
    }
    
    window.onload=checkCount;
    
    </script> 
    </head>
    
    <body>
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Try

    Code:
    window.onload="setTimeout(checkCount,10000)";   // 10 seconds delay
    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, i got it running by myself, but thanks for the help

    Code:
    function checkCount() {
      var count = GetCookie('count');
      if (count == null) {
        count=1;
        SetCookie('count', count, exp);
    	setTimeout(function() {
    		window.open(page, "", windowprops);
    	}, 120000);
    Last edited by rrwirks; 01-30-2013 at 08:12 AM. Reason: EDIT: solution


  •  

    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
    •