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

C

Carl Read

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.
 
J

Jonas Raoni

Carl said:
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 =]
 
C

Carl Read

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 said:
Carl said:
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 =]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top