473,473 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cookies

57 New Member
Hi,

I have the following code for use in a cookie script that can change the stylesheet depending upon what the visitor has decided on, here it is

Expand|Select|Wrap|Line Numbers
  1. function getcookie(c_name)
  2. {
  3. if (document.cookie.length>0)
  4.   {
  5.   c_start=document.cookie.indexOf(c_name + "=");
  6.   if (c_start!=-1)
  7.     { 
  8.     c_start=c_start + c_name.length+1 ;
  9.     c_end=document.cookie.indexOf(";",c_start);
  10.     if (c_end==-1) c_end=document.cookie.length
  11.     return unescape(document.cookie.substring(c_start,c_end));
  12.     } 
  13.   }
  14. return "vista"
  15. }
I was wondering how I could get this to work through different browser sessions because at the moment it is reverting back to the original everytime the page is loaded

Thnks in advance
Mar 9 '08 #1
5 907
Logician
210 New Member
I was wondering how I could get this to work through different browser sessions because at the moment it is reverting back to the original everytime the page is loaded
That is determined when the cookie is set. If you want a session cookie, don't specify a duration.

You're welcome in advance.
Mar 9 '08 #2
wangers16
57 New Member
I have set a duration, however it is still only working with browser sessions

Here is the code that set's the cookie, if that is any help

Expand|Select|Wrap|Line Numbers
  1. function createCookie(c_name,value,expiredays)
  2. {
  3. var exdate=new Date();
  4. exdate.setDate(exdate.getDate()+expiredays);
  5. document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
  6. }
and this is the button used to activate the command

Expand|Select|Wrap|Line Numbers
  1. <input type="button" value="Login" onClick="createCookie('style','old','1000000');">
Mar 9 '08 #3
Logician
210 New Member
This is the button used to activate the command

Expand|Select|Wrap|Line Numbers
  1. <input type="button" value="Login" onClick="createCookie('style','old','1000000');">
This suggests that when someone clicks a 'login' button, you're creating a fixed-value cookie, whereas you said initially that you're storing a user preference. I think you need to clarify exactly what happens and what you expect.
Mar 10 '08 #4
wangers16
57 New Member
Well the script is supposed write a user preference value to a cookie and that cookie is then later read by the computer and writes out a predefined stylesheet onto the site.

Now this does happen but it only happens per a user session only, whereas I need it to be able to be read at any browser session without the need of having to choose which style to use every time.
Mar 10 '08 #5
Logician
210 New Member
Well the script is supposed write a user preference value to a cookie and that cookie is then later read by the computer and writes out a predefined stylesheet onto the site.

Now this does happen but it only happens per a user session only, whereas I need it to be able to be read at any browser session without the need of having to choose which style to use every time.
You have shown no code that reads a user preference and writes it to a cookie.
You showed a Login button setting some cookie to a fixed value. If that's the same cookie, then obviously any value it stores is being reset whenever that button is clicked.
Mar 10 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
9
by: | last post by:
Is it possible for a user to enable permanent cookies but disable session cookies.....this seems like a contradition yet this is what I appear to be reading in online articles?
1
by: John Taylor-Johnston | last post by:
I'm a University academic looking for a proper definition of JavaScript Cookies. http://www.CollegeSherbrooke.qc.ca/languesmodernes/604-HAE_Grammar_Practice/ I'm trying to decipher what...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
8
by: CDARS | last post by:
Hi all, I have a confusing question on ASP.NET cookies usage: 1> Response.Cookies("test").value = Now 2> Response.Write(Request.Cookies("test").value) 3> 4> Response.write("<hr>") 5>...
6
by: Stephane | last post by:
Hi, I have a login page where if the user wants his access codes to be saved are set into a cookie. In the logout page, I want to delete those cookies. I tried this and this is not working at...
1
by: Alex Nitulescu | last post by:
I have the following very simple colde (while learning about cookies and session state): Private Sub cmdAddCookie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
0
by: Claudio | last post by:
I have a demo app where cookies does not work. The first page create a cookies. The second read the contet. If I browse the pages via IE6.0 the pages does not work. If I browse the pages via...
0
by: rn5a | last post by:
This is how I am creating & then reading cookies: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'create cookies Response.Cookies("UserName").Value = "Ron"...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.