[Javascript] Retrieving cookies and redirecting to another page
Rodney Myers
rodney at aflyingstart.net
Thu May 2 04:10:39 CDT 2002
var url=window.location.href;
var urlSplit=url.split("/");
Assuming the URL is "http://www.yourdomain.com/12345678"
then urlSplit is an Array with these element values:
0 http:
1
2 www.yourdomain.com
3 12345678
so you would use a setCookie function to save the value of urlSplit[3]
Then redirect to the index page
window.location="http://www.yourdomain.com/";
And in that page pick up the cookie
writing this code in a function that is invoked by the onLoad event in
<body>
var rfr = getCookie(cookiename);
document.formName.referrer.value=rfr;
You will need to test for the case where no cookie is set and adapt the
code.
setCookie / getCookie functions you can find in many books/websites.
hth
Rodney
Phillip Morgan wrote:
> Hi,
>
> I would like to grab part of a URL and write it to a cookie. Then go to
> another page.
>
> Eg. the incoming url might be http://www.yourdomain.com/12345678
>
> I want to grab the 12345678 and write that to a cookie, then I want to
> redirect the client to the main index.html page (equivelant of
> http://www.yourdomain.com).
>
> Or would the javascript to do this have to be on the index.html page,
> and the call the new page be to (eg), index2.html?
>
> I then want to read the cookie back later on a web page with a form and
> place the value (12345678), into a formfield called 'referrer'
>
> How would I do all this? There are no frames involved.
>
> --
> Phillip
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list