Forums

This topic is locked

Reading Cookies

Posted 28 Jan 2008 12:32:29
1
has voted
28 Jan 2008 12:32:29 marc tiss posted:
Hi, I'd really appreciate help with this problem - basically I have a set of style sheets that the user is able to pick from. Once they have chosen the style I want this to be remembered throughout the site but currently if they navigate to a different folder the style chosen is not remembered. I believe I have to alter the path of the cookie but don't know where this is adjusted. Script is as below:

<html><head><title>Style Switcher</title>
<script>
var StyleFile = "www.mysite.com/css/style" + document.cookie.charAt(6) + ".css";
document.writeln('<link rel="stylesheet" type="text/css" href="' + StyleFile + '">');
</script>
</head><body><h2>Live in Style</h2><br>
<a href="javascript: document.cookie='style='; window.location.reload();">Style 1</a> |
<a href="javascript: document.cookie='style=2'; window.location.reload();">Style 2</a> |
<a href="javascript: document.cookie='style=3'; window.location.reload();">Style 3</a>
</body></html>

Where would I add "path=/" if this is what's needed to make the cookie work throughout the site?

Many Thanks.

Replies

Replied 28 Jan 2008 18:48:54
28 Jan 2008 18:48:54 Vince Baker replied:
A cookie is stored against the domain name, so if you set a cookie on a page it will be available to call from any sub directory as long as it is within the same site (i.e. if you set a cookie in yoursite.com/index it will be callable in any other folder within yoursite.com/)

I am not a jscript coder myself but are you sure the cookie is being stored?

Try some tests to save a cookie and then somewhere on a page that should call it use <%=Request.cookies("style"%>


I would say this is either a syntax issue calling the cookie or a syntax error saving it.

RUn a couple of tests to see.


Regards

Vince Baker
<strong>DMX Zone Manager</strong>

[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]

Reply to this topic