473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript cookies?

I have been reading the post and the FAQ and have been unable to find
anything that will help with my problem.

First let me say that I am not a web developer, designer and no next to
nothing about javascript. I am just rebuilding my site and need help. We run
a bamboo nursery and the site has listings of over 100 varieties we sell.
The site uses regular pages and framesets for the discriptions of the
bamboo. The framesets have a top frame, left frame and main frame.

The left frame has a listing of all our varities which can be sorted in
several ways (height, diam. etc). Clicking on a variety loads the
description for the variety in the main frame. All of these files are
located in a directory called bamboo-frames.

We also have frames sets with the same layout that gives the user the
opprotunity to select a sub set of varieties by use. These files are located
in a directory called bamboo-uses but the lelt frame calls the description
page from the bamboo-frames directory.

The main frame for both the above sorts has the following starting mainframe
code:

Head
<script language=javascript
src="../bamboo-cookies/bamboo-cookies.js"></script>

body

<SCRIPT LANGUAGE="JavaScript">
<!--
var pic = getCookie("sizepic");
if (!pic) {
pic = "Full size";
setCookie('sizepic', pic);
}
// -->
</SCRIPT>

My html code

<form>
<input name="" type="button" onClick="setCookie('sizepic','Full size') "
value="Full size">
<input name="" type="button" onClick="setCookie('sizepic','Half size')"
value="Half size">
<input name="" type="button" onClick="alert(getCookie('sizepic'))"
value="Current size">
</form>

The functions were downloaded and pasted into bamboo-cookies.js

Clicking on the alert button will give the correct results regardless of the
starting main frame.

On the description pages if have the following code:

head
<script language=javascript
src="../bamboo-cookies/bamboo-cookies.js"></script>

body
My html

<SCRIPT LANGUAGE="JavaScript">
<!--
var pic = getCookie("sizepic");
switch(pic)
{
case "Full size":document.write("<img src='../bamboo-photos/bamboo-0105.jpg'
alt='Bamboo - P. bambusoides tanakae' width='480' height='640'
hspace='10'>");
; break
case "Half size": document.write("<img
src='../bamboo-photos50/bamboo-0105.jpg' alt='Bamboo - P. bambusoides
tanakae' width='240' height='320' hspace='10'>");
; break
default: document.write("<img src='../bamboo-photos/bamboo-0105.jpg'
alt='Bamboo - P. bambusoides tanakae' width='480' height='640'
hspace='10'>");
; break
}
//-->
</SCRIPT>

When calling the description page from the bamboo-frames directory the
correct size photo is download with the page.

When calling the description page from the bamboo-uses directory the last
size called from the bamboo-frames directory is used even though the buttons
apparently change the cookie value.

In the comments of the setCookie function it says the default directory is
path=/ so I do not pass a value.

I don't understand all that is happening but hope someone can see what I am
doing wrong. I have been trying to get this to work for 4 days now and am
really frustrated by my lack of knowledge.

Any guidance appreciated.

Bert

Jul 23 '05 #1
7 2196

"Bert" <be*********@meckcom.net> wrote in message
news:10*************@corp.supernews.com...
I have been reading the post and the FAQ and have been unable to find
anything that will help with my problem. (snip)
I don't understand all that is happening but hope someone can see what I am doing wrong. I have been trying to get this to work for 4 days now and am
really frustrated by my lack of knowledge.

Any guidance appreciated.

Bert


On further searching I have found the following:

I have added a expire time- did not correct problem

The buttons on the bamboo-uses frameset main page return the value of the
cookie, however when I call the
bamboo-frames/description-mainframe page I get a null when the getCookie
function is called and the switch default is executed.

Maybe this will help in recommending a solution.

Bert

Jul 23 '05 #2
In article <10*************@corp.supernews.com>,
"Bert" <be*********@meckcom.net> wrote:
"Bert" <be*********@meckcom.net> wrote in message
news:10*************@corp.supernews.com...
I have been reading the post and the FAQ and have been unable to find
anything that will help with my problem. (snip)
I don't understand all that is happening but hope someone can see what I

am
doing wrong. I have been trying to get this to work for 4 days now and am
really frustrated by my lack of knowledge.

Any guidance appreciated.

Bert


On further searching I have found the following:

I have added a expire time- did not correct problem


Best to set the expiration time. Sometimes IE gets confused.
The buttons on the bamboo-uses frameset main page return the value of the
cookie, however when I call the
bamboo-frames/description-mainframe page I get a null when the getCookie
function is called and the switch default is executed.

Maybe this will help in recommending a solution.

Bert


Maybe you are hitting some security restriction.

When you do not specify a path parameter, your client needs to load all
the html file from the same directory or any subdirectory of the
directory.

See the path parameter and domain parameter to relax what html pages can
read the cookie.

Did this code work before? What was changed just before the code
stopped working?

Could you give a URL?

Robert
Jul 23 '05 #3
In article <10*************@corp.supernews.com>,
"Bert" <be*********@meckcom.net> wrote:

Codes are more difficult than they appear.

Try the page in Netscape 7.1 (gekco). In Netscape 7.1 you can use the
cookie manager to see your cookies. This way you can verify that a
cookie has been set. You can turn on privacy and security -> cookies ->
"ask me before storing a cookie" to see when a cookie is stored.

You can see your cookie files in IE too, but it isn't as easy as
Netscape imho.

Robert
Jul 23 '05 #4
"Robert" <rc*******@my-deja.com> wrote in message
news:rc*****************************@news4.west.ea rthlink.net...
In article <10*************@corp.supernews.com>,
"Bert" <be*********@meckcom.net> wrote:
"Bert" <be*********@meckcom.net> wrote in message
news:10*************@corp.supernews.com...
I have been reading the post and the FAQ and have been unable to find
anything that will help with my problem.

(snip)
I don't understand all that is happening but hope someone can see what I
am
doing wrong. I have been trying to get this to work for 4 days now and
am really frustrated by my lack of knowledge.

Any guidance appreciated.

Bert


On further searching I have found the following:

I have added a expire time- did not correct problem


Best to set the expiration time. Sometimes IE gets confused.

The buttons on the bamboo-uses frameset main page return the value of

the cookie, however when I call the
bamboo-frames/description-mainframe page I get a null when the getCookie
function is called and the switch default is executed.

Maybe this will help in recommending a solution.

Bert


Maybe you are hitting some security restriction.

When you do not specify a path parameter, your client needs to load all
the html file from the same directory or any subdirectory of the
directory.

See the path parameter and domain parameter to relax what html pages can
read the cookie.

Did this code work before? What was changed just before the code
stopped working?

Could you give a URL?

Robert


Thanks Robert,

I am still working on the site on my local machine so no url yet.

The code never worked I am just trying to get it to.

Thanks for the advice and suggestions. I will try NetScape to see if I can
find anything when I get time. I have decided not to use the code in the
USES directory until I have time to try to learn enough to understand what
is happening.

Again thanks and I will be back later when I try to get it working.

I also want to express my thanks to all the folks that post here What I have
learned so far is from reading the post.

Bert
Jul 23 '05 #5
Robert <rc*******@my-deja.com> wrote in message news:<rc*****************************@news4.west.e arthlink.net>...
In article <10*************@corp.supernews.com>,
"Bert" <be*********@meckcom.net> wrote:

Codes are more difficult than they appear.

Here are my suggestions.

1) Always set the expiration time. IE works better.

2) You may have disabled cookies. In IE, I had to go to the site then
check whether or not cookies were enabled.

3) Maybe your cookie rountines could use improvements.
I suggest using an existing set of cookie routines. The
document.cookie can contain existing cookies and you need to preserve
them. ( Don't know why such routines aren't shipped with the browsers.
)
~kaeli~ has developed some cookie code. You may view it in this
article:

http://groups.google.com/groups?hl=e...859-1&selm=MPG
..1af96c2a4f8abc94989dcc%40nntp.lucent.com

Also, ~kaeli~ reports that:
There's some even better code that sets more cookie properties like
domain, secure, path, etc here.
http://www.acm.uiuc.edu/webmonkeys/j...ipt/cookies.js

4) I wrote a short program for verifying cookies will work on a site.
The cookie code was taken from:
Functions from Using HTML 4, Java 1.1, and JavaScript 1.2:
Complete. Definitive. Invaluble.
by Eric Jim O'Donnell, et al.
and from the Netscape develper's site. Here is my cookie testing
code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Remember by cookie</title>
<script type="text/javascript">
// Sets cookie values. Expiration date is optional
//
function setCookie(name, value, expire) {
document.cookie = name + "=" + escape(value)
+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}

function deleteCookie(name,path,domain) {
if (getCookie(name)) document.cookie = name + "=" +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function registerCookie(cookieName,cookieValue) {
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
setCookie(cookieName, cookieValue, expires)
}
</script>

<body>
<p>Let's see if we can set then read a cookie
<script type="text/javascript">
document.write("when on (document.url) " + document.URL);
document.write("</p>");

var all = "I hope this cookie doesn't crumble.";

document.write("<p>");
document.write("document.cookie before deleteCookie = "
+ document.cookie + "<br><br>");
deleteCookie("mycookietry");
document.write("document.cookie after deleteCookie= "
+ document.cookie + "<br><br>");

registerCookie("mycookietry",all);

document.write("document.cookie after registerCookie = "
+ document.cookie + "<br><br>");

theMessage = getCookie("mycookietry");
document.write("theMessage = " + theMessage + "<br>");
document.write("</p>");
</SCRIPT>
</body>
</html>
Jul 23 '05 #6

"Robert" <rc*******@my-deja.com> wrote in message
news:c6**************************@posting.google.c om...
Robert <rc*******@my-deja.com> wrote in message

news:<rc*****************************@news4.west.e arthlink.net>...
In article <10*************@corp.supernews.com>,
"Bert" <be*********@meckcom.net> wrote:

Codes are more difficult than they appear.

Here are my suggestions.

1) Always set the expiration time. IE works better.

2) You may have disabled cookies. In IE, I had to go to the site then
check whether or not cookies were enabled.

3) Maybe your cookie rountines could use improvements.
I suggest using an existing set of cookie routines. The
document.cookie can contain existing cookies and you need to preserve
them. ( Don't know why such routines aren't shipped with the browsers.
)
~kaeli~ has developed some cookie code. You may view it in this
article:

http://groups.google.com/groups?hl=e...859-1&selm=MPG
.1af96c2a4f8abc94989dcc%40nntp.lucent.com

Also, ~kaeli~ reports that:
There's some even better code that sets more cookie properties like
domain, secure, path, etc here.
http://www.acm.uiuc.edu/webmonkeys/j...ipt/cookies.js

4) I wrote a short program for verifying cookies will work on a site.
The cookie code was taken from:
Functions from Using HTML 4, Java 1.1, and JavaScript 1.2:
Complete. Definitive. Invaluble.
by Eric Jim O'Donnell, et al.
and from the Netscape develper's site. Here is my cookie testing
code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Remember by cookie</title>
<script type="text/javascript">
// Sets cookie values. Expiration date is optional
//
function setCookie(name, value, expire) {
document.cookie = name + "=" + escape(value)
+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}

function deleteCookie(name,path,domain) {
if (getCookie(name)) document.cookie = name + "=" +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function registerCookie(cookieName,cookieValue) {
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
setCookie(cookieName, cookieValue, expires)
}
</script>

<body>
<p>Let's see if we can set then read a cookie
<script type="text/javascript">
document.write("when on (document.url) " + document.URL);
document.write("</p>");

var all = "I hope this cookie doesn't crumble.";

document.write("<p>");
document.write("document.cookie before deleteCookie = "
+ document.cookie + "<br><br>");
deleteCookie("mycookietry");
document.write("document.cookie after deleteCookie= "
+ document.cookie + "<br><br>");

registerCookie("mycookietry",all);

document.write("document.cookie after registerCookie = "
+ document.cookie + "<br><br>");

theMessage = getCookie("mycookietry");
document.write("theMessage = " + theMessage + "<br>");
document.write("</p>");
</SCRIPT>
</body>
</html>


Thanks Robert. Now I am on my next problem.

Bert
Jul 23 '05 #7
JRS: In article <10*************@corp.supernews.com>, seen in
news:comp.lang.javascript, Bert <be*********@meckcom.net> posted at Fri,
16 Jul 2004 18:51:29 :
Lines: 131


function registerCookie(cookieName,cookieValue) {
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
setCookie(cookieName, cookieValue, expires)
}
The number 1000*60*60*24 is more economically written 864e5.

I see no need for having today as well as expires.

expires.setMonth(expires.getMonth()+12)

is simpler, and gets to the present time & date a year ahead (if
possible; else reasonable substitute). Note the avoidance of
getYear/getFullYear. If you really want 365 days,

expires.setDate(expires.getDate()+365)

with the same caveat about the time only.

</html>


Thanks Robert. Now I am on my next problem.


Please do not over-quote.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass...
2
by: Michael | last post by:
I am reading and setting a cookie using JavaScript in the BODY onload and onunload events respectively. This works fine. However when I use ASP to set the cookie under some condition where I...
1
by: Mike | last post by:
Hello, I want to read and write key'ed cookies from both javascript and ASP. I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP like the...
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...
9
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET...
1
by: FishKeeper | last post by:
I'm trying to write JavaScript code to test whether cookies are enabled by writing a cookie and then reading its value. My code works fine in Firefox, but it's not working in Internet Explorer 6. ...
16
by: retyop | last post by:
Does javascript install any sort of "cookies" that allows a site to uniquely identify you every time you visit, regardless of wether or not you disable normal web browser cookies? An anonymous...
2
by: HopfZ | last post by:
Server sends cookie to browser and the browser send the same cookie back to the server according to Wikipedia. Do browsers send even javascript-generated cookie to servers? For example, if I...
3
by: WayneH | last post by:
Hi - I'm trying to use javascript to determine if a user's browser has cookies enabled or not. To test: copy this code into a file with a 'html' extension, and load it into your IE browser...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.