473,396 Members | 2,002 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.

simple javascript cookie question

Hi guys,

I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referrer
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.

Many thanks

Alex
Hot Tubs 2 Buy.co.uk

Your help would be much apreciated.

Sep 5 '06 #1
6 2087
alex.kemsley wrote on 05 sep 2006 in comp.lang.javascript:
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referrer
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.
How can we know the script is so simple
if you do not show us wat you wrote?

What is a "formail"?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '06 #2
form mail.
As in an email program that sends you the content in a form.
Thank
Alex

Evertjan. wrote:
alex.kemsley wrote on 05 sep 2006 in comp.lang.javascript:
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referrer
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.

How can we know the script is so simple
if you do not show us wat you wrote?

What is a "formail"?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '06 #3
alex.kemsley wrote on 05 sep 2006 in comp.lang.javascript:
Evertjan. wrote:
>alex.kemsley wrote on 05 sep 2006 in comp.lang.javascript:
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referrer
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail
so i can see how people got to my website and where they entered.

How can we know the script is so simple
if you do not show us wat you wrote?

What is a "formail"?
[please do not toppost on usenet]
form mail.
As in an email program that sends you the content in a form.
Is that a clientside thing? Or do you simply send the daa to servrside to
be processed, and if so how?

Because you did toppost,
you did not consider my first and far more important question:
What code did you come up with?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '06 #4
*** alex.kemsley escribió/wrote (5 Sep 2006 07:13:54 -0700):
I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable
[...]
I need this cookie to last just one day.
I compiled these functions some time ago, I hope it helps. (I've just translated the names from Spanish using Search & Replace, I hope I didn't break it)
/*
* Creates a cookie - name [value] [timeToExpire (s)] [path] [domain] [secure (bool)]
*/
function createCookie(name, value, timeToExpire, path, domain, secure){ // v2005-03-02
if(timeToExpire){
var expires=new Date();
expires.setUTCMilliseconds(expires.getUTCMilliseco nds()+1000*timeToExpire);
}

document.cookie=escape(name) + '=' + (value? escape(value) : '') +
(expires? '; expires=' + expires.toGMTString() : '') +
(path? '; path=' + escape(path) : '') +
(domain? '; domain=' + escape(domain) : '') +
(secure? '; secure' : '');
}
/*
* Removes a cookie
*/
function removeCookie(name){ // v2005-03-02
createCookie(name, '', -86400*365*10);
}
/*
* Returns the value of a cookie (null if it doesn't exist)
*/
function readCookie(name){ // v2005-02-27
eval('var re=/^('+escape(name)+')=(.*)$/i;');
var c=document.cookie.split(/;\s*/);

for(var i in c){
if(re.test(c[i])){
return unescape(re.exec(c[i])[2]);
}
}
return null;
}

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 5 '06 #5
JRS: In article <v1**************************@40tude.net>, dated Wed, 6
Sep 2006 00:13:20 remote, seen in news:comp.lang.javascript, Alvaro G.
Vicario <we*******@NOSPAMdemogracia.composted :
>I need this cookie to last just one day.

I compiled these functions some time ago, I hope it helps. (I've just translated
the names from Spanish using Search & Replace, I hope I didn't break it)
If you had likewise replaced Tab with Space Space, it would have been
easier to read.

var expires=new Date();
expires.setUTCMilliseconds(expires.getUTCMilliseco nds()+1000*tim
eToExpire);
That has (FWIW) an error of the present fraction of a second, and ISTM
may use conversions to/from YMD internally.

expires.setTime( +expires + 1000*timeToExpire )
or just
expires=new Date( +new Date() + 1000*timeToExpire )
>function removeCookie(name){ // v2005-03-02
createCookie(name, '', -86400*365*10);
}
Is it necessary to go 10 years ago?

eval('var re=/^('+escape(name)+')=(.*)$/i;');
Function eval should not be needed.

It's a good idea to read the newsgroup and its FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 6 '06 #6
"alex.kemsley" <al**********@hottubs2buy.co.ukwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi guys,

I am trying to write a simple script in vain.
I need it to first check to see if the cookie exists
then if not
write one with two variable

var ref = document.referrer
var page = location.href

I need this cookie to last just one day.

This script is going to be used to send me this info in my formail so i
can see how people got to my website and where they entered.
I've a cookie abstraction library that might help here:

http://www.depressedpress.com/Conten...kies/Index.cfm

There is one sorta bug in this version (which I hope to fix tomorrow): the
erase() method doesn't accept a path or domain which means it will fail with
cookies which set path and domain (instead of deleting the named cookie it
will create a second cookie without the path or domain).

If you're not doing that then it should work, if you are don't use the
erase() method for now and instead reset the cookie (the set() method) to a
past date to delete it.

Jim Davis
Sep 9 '06 #7

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

Similar topics

1
by: mark leeds | last post by:
i am not a javasript programmer by any stretch but i have been writing a javascript programmer for a friend that does the following : 1) prompts the user for first name, middle name and last...
7
by: Steph | last post by:
Bonjour, Je souhaite lancer une redirection vers un fichier php via SRC= dans une condition if (voir ci-dessous en bas du script) mais la redirection ne fonctionne pas. Par contre la condition...
0
by: JT | last post by:
I posted a question earlier about communicating between a javascript function and vb.net. In the end I decided to try using a cookie. I use the following javascript function (from vb.net) to set...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...

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.