0

I have a code that has no syntax errors (Dreamweaver) but the Chrome JS console is saying that ExistsCookie is undefined. The cookie was in the cookie list for that site but the page is not redirecting. What am I doing wrong? NOTE: I know people can turn cookies off.

var cname = "voicevote"
var data ="1";


function CheckForCookie()
{
  if( ExistsCookie(cname) )
   {
     window.location.replace("cookie.htm")
   }
}
4

1 に答える 1

1

Most likely, ExistsCookie is a function that you haven't included in your script- if this was taken from a tutorial on some other website, look there- there may be a function on that page which you forgot to include in your code.

EDIT: After some googling, it looks like this is what you need:

function ExistsCookie(name)
 {
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (name == aCrumb[0]) 
      return true;
  }

  return false;
}

(Source, which appears to match original question)

于 2012-11-18T01:59:13.087 に答える