www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help Please.

  1. #1
    Join Date
    Sep 2005
    Posts
    15

    Help Please.

    I have a cookie that sets the colour on the homepage when you click on an option, the page turns blue then if you click a hyperlink to another part of the website that page also changes colour(Good So Far) if you then change colour on this page and return to the previous one the previous one still has its original colour how do i solve this here is my cookie script

    <script type="text/javascript"><!--
    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 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" : "");
    }
    // -->
    </script>


    Thi is placed on all pages i want to have remember the colour selection.

  2. #2
    Join Date
    Aug 2005
    Location
    The Hill Ch' Hill
    Posts
    381
    a better way than to send cookies for this operation would be to use the titlebar.
    About 20% of people disable cookie support from their browser due to secuirty concerns.

    Use the titlebar such as <a href="newPage.html?colour=blue">Click Me</a>

    The "?colour=blue" part can be retrieved from the page just opened i.e. newPage.html
    by using the window.search property.

    When you have eliminated the impossible, whatever remains, however improbable, must be the truth !


    [Sir Arthur Conan Doyle]

Thread Information

Users Browsing this Thread

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

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