Results 1 to 2 of 2

Thread: Redirect By Cookie

  1. #1
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Redirect By Cookie

    I found this script:

    External:
    Code:
    // Redirect Cookie 2
    // Version 1.10
    // Written by Chris Hansen.
    // Copyright  1999-2003 by Chris Hansen.
    
    function getCookieVal(offset){
      var endstr = document.cookie.indexOf(";", offset);
      if (endstr == -1)
        endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }
    
    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 "";
    }
    
    function SetCookie(name, value){
      expDays = 365;
      exp = new Date();
      exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
    
      document.cookie = name + "=" + escape(value) + "; expires=" + exp.toGMTString();
    }
    
    function cRedirect(value){
      SetCookie("cChoise", value);
    }
    
    function IsCookieSet()
    {
      var redirpage = GetCookie("cChoise");
      if (redirpage != "") {window.location = redirpage;}
    }
    Head:
    Code:
    function menuRedirect(){
        var select = eval(document.redirectForm.elements[0].selectedIndex);
        var choise1 = "choise1.html";
        var choise2 = "default/index.html";
    
        if (select==0) void(0);
        else if (select==1) {window.open(choise1,"_top"); cRedirect(choise1);}
        else if (select==2) {window.open(choise2,"_top"); cRedirect(choise2);}
      }
    Menu:
    Code:
        <FORM name="redirectForm">
          <TABLE border="1" cellspacing="0" cellpadding="0">
            <TR>
              <TD>
                <SELECT name="menu" onChange="menuRedirect()">
                  <OPTION value="1">Make A Choise</OPTION>
                  <OPTION value="2">Choise 1</OPTION>
                  <OPTION value="3">Choise 2</OPTION>
                </SELECT>
              </TD>
            </TR>
          </TABLE>
        </FORM>
    I've found 2 problems, 1 if I try to change anything, the cookie part (top) has to be removed otherwise nothing happens, I suspect theres an ID I'm missing and not changing, but thats minor. For some reason, whenever I run that in my browser it doesn't remember after a close. I looked it over and tried changing a few things, but no luck.

  2. #2
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    This is what the code in the head should be. Notice the onload event is the only change

    Code:
    function menuRedirect(){
        var select = eval(document.redirectForm.elements[0].selectedIndex);
        var choise1 = "choise1.html";
        var choise2 = "default/index.html";
    
        if (select==0) void(0);
        else if (select==1) {window.open(choise1,"_top"); cRedirect(choise1);}
        else if (select==2) {window.open(choise2,"_top"); cRedirect(choise2);}
      }
    window.onload=IsCookieSet;

Bookmarks

Posting Permissions

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