cookie problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alain dhaene

    cookie problem

    Hi,

    I get the follow problem.

    A page is locate in C:\Directory\fi les\pag1.php
    There I call the function setUrl. (all the functions are located in
    C:\Directory\in cludes

    function setUrl()
    {

    var ckyDatum = new Date;
    ckyDatum.setDat e(ckyDatum.getD ate()+7);

    var href = document.locati on.href;
    the_cookie = escape(href);

    document.cookie = 'test=' + the_cookie + '; path=/;' ;
    alert(document. cookie);

    }

    This is OK : the alert results in ' test =
    C\Directory\fil es\pag1.php


    In a page located in C:\Directory\su b\pag5.php I call the function getUrl
    <script language="JavaS cript">
    getUrl();
    </script>

    function getUrl()
    {

    var resultaat;

    resultaat = leesUrl('test') ;
    alert(resultaat ); //OK
    The alert results in
    C\Directory\fil es\pag1.php

    document.write ("<a href="+ resultaat + "><img
    border='0'src=' ../afbeeldingen/Algemeen/terugbr.gif'></a>");

    !!!!!!!!!!!!!!! !!!//this is not good. I get the follow a href:
    C:\Directory\su b\c\Directory\f iles\pag1.php


    }



    function leesUrl(cookieN ame)

    {


    cookie_array = document.cookie .split ("; ")

    for (x=0; x < cookie_array.le ngth; x++)
    {
    cookieParts_arr ay = cookie_array[x].split("=")
    if (cookieParts_ar ray[0] == cookieName)
    {
    alert (cookieParts_ar ray[1]);
    return cookieParts_arr ay[1];
    }
    }
    }

    What's wrong?

    Alain


  • Stephen Chalmers

    #2
    Re: cookie problem


    "alain dhaene" <a.dhaene@instr uct.be> wrote in message
    news:40adca86$0 $9876$a0ced6e1@ news.skynet.be. ..
    [color=blue]
    > The alert results in
    > C\Directory\fil es\pag1.php
    >
    > document.write ("<a href="+ resultaat + "><img[/color]
    border='0'src=' ../afbeeldingen/Algemeen/terugbr.gif'></a>");[color=blue]
    >
    > !!!!!!!!!!!!!!! !!!//this is not good. I get the follow a href:
    > C:\Directory\su b\c\Directory\f iles\pag1.php
    >
    >
    > What's wrong?
    >[/color]
    document.write will interpret backslashes in a string as escape characters
    unless they are themselves escaped \\.
    Easier to specify URLs using forward slashes '/' only.

    --
    S.C.


    Comment

    Working...