#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    4
    Rep Power
    0

    Cookie help required please (javascript newbie)


    Goal : To write a cookie which stores the referring website and then writes this referrer into an order form if the visitor orders a service.

    Reason : To improve advertising effectivenss.

    Ok guys, this is what I have got so far. It's my first attempt at a cookie, let alone javascript. This will write the referrer to the page (next step is to get that into a form)... but now I can't :

    1. Get the cookie to check if it already exists and not write anything if it does (so it only ever writes the first time someone visits).

    2. Get another page to read the cookie.

    <script language="javascript">
    cookie_name="mylittlecookie";
    var exp = new Date()
    var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000)
    exp.setTime(oneYearFromNow)
    var qasdf = document.referrer
    document.cookie = "referred by " + escape( document.referrer ) + "; expires=" + exp.toGMTString();
    document.write (qasdf);
    </script>

    Could anyone assist me with this please?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    NYC
    Posts
    79
    Rep Power
    12
    Having defined cookie_name, why not use it?
    Cookies (values) are not supposed to contain spaces, commas, or semicolons, so maybe
    document.cookie = cookie_name + "=" + escape("referred by " + document.referrer ...
    Also, there is no need for putting Newbie in the post title.

    Csaba

IMN logo majestic logo threadwatch logo seochat tools logo