Help With Accessing Cookies When Web Pages Are Located in Different Folders

Discussion in 'Javascript' started by Carl Read, Feb 23, 2006.

  1. Carl Read

    Carl Read Guest

    Hi,

    First I would like to state that I am not a JavaScript expert.

    I have a simple shopping basket that uses cookies. The problem is that all
    the product pages and basket must be in the the same folder.

    I was wondering if it is possible to create and save a cookie so that it can
    be accessed and viewed by HTML pages that are located in various different
    folders?

    Here is the code relating to the cookie:

    document.cookie='TheBasket='+document.cookie.substring(countbegin,countend)+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newURL+'|'+newQuantity+'];
    expires= '+today+'';

    index=document.cookie.indexOf('TheBasket');


    Thanks,

    Carl.
     
    Carl Read, Feb 23, 2006
    #1
    1. Advertising

  2. Carl Read

    Jonas Raoni Guest

    Re: Help With Accessing Cookies When Web Pages Are Located in DifferentFolders

    Carl Read wrote:
    > First I would like to state that I am not a JavaScript expert.


    That's great, there are quite a lot of people here that think they're
    experts, all programmers should be modest :)


    > Here is the code relating to the cookie:
    > document.cookie='TheBasket='+document.cookie.substring(countbegin,countend)+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newURL+'|'+newQuantity+'];
    > expires= '+today+'';
    >
    > index=document.cookie.indexOf('TheBasket');


    You can set a "path" property for the cookie, which specifies the
    initial directory that will have access to the cookie, take a look here
    <URL:http://php.net/set_cookie> and you'll understand.

    I suggest you to use a cookie library, it's quite annoying to write it
    manually =/

    The first google result that I got
    <URL:http://techpatterns.com/downloads/javascript_cookies.php>

    Good luck =]


    --
    Jonas Raoni Soares Silva
    http://www.jsfromhell.com
     
    Jonas Raoni, Feb 23, 2006
    #2
    1. Advertising

  3. Carl Read

    Carl Read Guest

    Thanks,

    After playing around is seemed that once the path was set to the root
    directory the cookies worked across folders.

    document.cookie='TheBasket='+document.cookie.substring(countbegin,countend)+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newURL+'|'+newQuantity+'];
    path=/; expires= '+today+'';

    Thanks for the help.



    "Jonas Raoni" <> wrote in message
    news:dtkppm$846$...
    > Carl Read wrote:
    >> First I would like to state that I am not a JavaScript expert.

    >
    > That's great, there are quite a lot of people here that think they're
    > experts, all programmers should be modest :)
    >
    >
    >> Here is the code relating to the cookie:
    >> document.cookie='TheBasket='+document.cookie.substring(countbegin,countend)+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newURL+'|'+newQuantity+'];
    >> expires= '+today+'';
    >>
    >> index=document.cookie.indexOf('TheBasket');

    >
    > You can set a "path" property for the cookie, which specifies the initial
    > directory that will have access to the cookie, take a look here
    > <URL:http://php.net/set_cookie> and you'll understand.
    >
    > I suggest you to use a cookie library, it's quite annoying to write it
    > manually =/
    >
    > The first google result that I got
    > <URL:http://techpatterns.com/downloads/javascript_cookies.php>
    >
    > Good luck =]
    >
    >
    > --
    > Jonas Raoni Soares Silva
    > http://www.jsfromhell.com
     
    Carl Read, Feb 24, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joo Park
    Replies:
    1
    Views:
    288
    bruce barker
    Feb 18, 2005
  2. sravan_reddy001
    Replies:
    6
    Views:
    578
    Munna
    May 19, 2008
  3. _Who
    Replies:
    7
    Views:
    2,681
  4. bb
    Replies:
    0
    Views:
    562
  5. Pasha
    Replies:
    7
    Views:
    102
Loading...

Share This Page