FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Cookies help

 


mantasx
I need help with this and I've hadn't gotten any ansers but to use cookies. I'm a tatal noob so please don't get mad or say google 'cookies'. I want to make a javascript that will redirect users to a different site only once. The second time they would visit they would stay in the same page. Someone on mirc tald me that I should use cookies, and thats the only way out. It would make sence.., I've been google'in for 4 days!!! Crying or Very sad So please be kind to share a code, or share a link to a website, or anything that would help me explain how to make my dream true. Thanks.
MrBlueSky
This should work:

Code:

<SCRIPT language="JavaScript">

var cookies = document.cookie;
var pos = cookies.indexOf("visit=");

function firsttime() {

  if (pos != -1) {
    var start = pos + 6;
    var end = cookies.indexOf(";", start);
    if (end == -1) end = cookies.length;
    var value = cookies.substring(start, end);
 
    if (value == "yes")
      return false;
  } 
  return true;
 
}

if (firsttime()) {
  document.cookie = "visit=yes; max-age=" + (60*60*24*365);
  window.location.href="http://www.google.com";
}

</SCRIPT>


Replace http://www.google.com with the url of the site were the visitor must be directed to the first time.

I only tested it in IE7 and Opera
mantasx
Thank You So Much!!!! Very Happy This was exactly what I was looking for! Your the best! Cool
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.