[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cookies (how to use them?)
I'm not sure if this will help, but it might put you on the right track
for your cookie problem.
I used this cookie to have a new visitor pushed to a policy page and once
they accept the policy, they aren't automatically linked to the policy
page.
Use this JavaScript to have the document recognize to the cookie. When
they come on, use the onLoad command in the body to reference a function
that checks the cookie.
Then use the onUnload command to set the cookie so when they leave, the
cookie is told that they have visited the site.
The function UpStart at the end checks the cookie.
But I used a form to set the cookie, you'd have to write a separate
function to set yours.
<script>
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString()))
+
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1); // This cookie is history
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" +
exp.toGMTString();
}
function UpStart () {
window.close();
if(GetCookie('DemoName') == 'Pol3051'){
window.open('http://gww.geps.ge.com');
}
else {
window.open('http://weber.geps.ge.com/policies/pol3051.htm');
}
}
>
> From: kristian@generation.net (Christian Lanctot)
> Date: Wed, 20 Mar 1996 22:23:49 -0500
> Subject: Cookies (how to use them?)
>
> Help!
>
> How do you use cookies in javascript. I'm still not quite clear
on
> this. What i want to do is set a cookie when a user comes into my site.
And
> the next time he comes back, read that coockie and display the proper
> information.
>
> I want to use it so that a user can enter his name and a couple
of
> settings (preferences) and save them into different cookies that i will
> recall whenever the user comes back to my page. I've read the Docs on
> Cookies, but there really isn't any practical information that i've
found
> that relates to using Cookies with Javascript.
>
> Anybody know of a tutorial or FAQ for setting and recalling
cookies
> with JavaScript?
>
> thanks.
--------------------------------------------------------------------
For help about the list, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.
List archives and pointer to FAQ: http://www.obscure.org/javascript/