www.webdeveloper.com
Results 1 to 2 of 2

Thread: Cookies help with coding!

  1. #1
    Join Date
    Apr 2007
    Location
    Minnesota
    Posts
    17

    Unhappy Cookies help with coding!

    Alright, I have a basic code I found at JavaScript Kit

    I would kindly like some help getting code to open an alert box when they close or leave a certain domain. The following script is from the above mentioned site.

    Code:
    <script type="text/javascript">
    //Get cookie routine by Shelley Powers
    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) {
    offset += search.length
    // set index of beginning of value
    end = document.cookie.indexOf(";", offset);
    // set index of end of cookie value
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function setcolor(what){
    document.body.style.backgroundColor=what
    document.cookie="bgcolor="+what
    }
    
    if (get_cookie("bgcolor")!="")
    document.body.style.backgroundColor=get_cookie("bgcolor")
    
    </script>
    Is there a way to modify this section
    Code:
    function setcolor(what){
    document.body.style.backgroundColor=what
    document.cookie="bgcolor="+what
    }
    
    if (get_cookie("bgcolor")!="")
    document.body.style.backgroundColor=get_cookie("bgcolor")
    or whichever section needs the alert code, so that it calls up an alert box?

    Please help. I'm not a JS expert I only have basic knowledge and right now I do not have resources or time to fully "learn" the expansive amount of JS knowledge to create this code myself.

    Thanks!
    Metallifan15

  2. #2
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    document.cookie="bgcolor="+what needs to be escaped, You have no expiry or other important bits that go with a cookie.

    If you search this forum for cookies, you will find plenty of examples that you can use and modify for your needs.

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