Click to See Complete Forum and Search --> : Insterting cookie into URL


eclipse88
07-13-2004, 10:45 PM
HI

How would I grab a cookie and put it inside a url string?

here's what I have so far:

<script>

Function playthis(theURL,chyron)
{

Var fullURL = "/live/video_top.asp?videoSrc=" + theURL + <cookiehere> + "&chyronSrc=" + chyron

}

</script>

here's the linK:

<a href="playthis('http://www.myurl.com/','/live/test.html')">play</a>

steelersfan88
07-13-2004, 10:55 PM
Nice Little Cookie Tutorial Here (http://home.cogeco.ca/~ve3ll/jstutor9.htm) that you could use. Just add the three functions. Then, to receive the value of the cookie, and put into the string, use:var fullURL = "/live/video_top.asp?videoSrc=" + theURL + EatCookie('url') + "&chyronSrc=" + chyronassuming the name given to the cookie when you "baked" it [BakeCookie(name,value)] was url. That should do it.

Dr. Script

eclipse88
07-13-2004, 11:10 PM
this doesnt seem to work
what happens after the var fullURL?

how is that called?

steelersfan88
07-13-2004, 11:13 PM
Pull a combo between both threads, and you'll get it.
To have your cookie scripts, just add this to the page head:<script type="text/javascript">

function BakeCookie(name,value) {
var argv=arguments;
var argc=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.toUTCString())) +
((path === null) ? "" : ("; path="+path)) +
((domain === null) ? "" : ("; domain="+domain)) +
((secure === true) ? "; secure" : "");
}

function EatCookie(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 EatCookieVal(j);
}
i=document.cookie.indexOf(" ",i) + 1;
if (i === 0) {break;}
}
}

function EatCookieVal(offset) {
var endstr=document.cookie.indexOf(";",offset);
if (endstr == -1) {endstr=document.cookie.length;}
return unescape(document.cookie.substring(offset,endstr));
}

</script>Then, simply write the cookie as:BakeCookie('name','John')and read it asalert(EatCookie('name')) // alerts JohnDr. Script