Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Can't get this script to write the cookie


  • From: javascript@xxxxxxxxxx (Phillip Morgan)
  • Subject: [Javascript] Can't get this script to write the cookie
  • Date: Fri, 31 May 2002 14:49:42 +1000

This is a multi-part message in MIME format.

------=_NextPart_000_0003_01C208B2.65F2B140
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi,
 
I'm having problems getting this script to work. It is intended to grab
the query string from the URL and then write that to a cookie which is
later retrieved on another page. Can anyone help please....
 
 
 <script language="JavaScript">
    <!-- Hide this script from old browsers
 
 // Set the expiry date for cookie - valid for 30 days
 var expDate = new Date();
      expDate.setTime( expDate.getTime() + ( 24 * 3600 * 30000 ) );
 var qryString;
 var myId;
 var x;
 
 qryString = window.location.search;
 x = qryString.indexOf("=");
 myId = qryString.substring((x + 1),qryString.length)
 
 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" : "" );
      }
 
 // Write cookie.
setCookie('QLTReferrer',myId, expDate, cookiePath );
 
// -->
</script>

------=_NextPart_000_0003_01C208B2.65F2B140
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<TITLE>Message</TITLE>

<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D620214004-31052002>Hi,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D620214004-31052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D620214004-31052002>I'm =
having problems=20
getting this script to work. It is intended to grab the query string =
from the=20
URL and then write that to a cookie which is later retrieved on another =
page.=20
Can anyone help please....</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D620214004-31052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D620214004-31052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&lt;script=20
language=3D"JavaScript"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;!-- Hide this =
script from=20
old browsers<BR>&nbsp;<BR>&nbsp;// Set the expiry date for cookie - =
valid for 30=20
days<BR>&nbsp;var expDate =3D new Date();<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;exp=
Date.setTime(=20
expDate.getTime() + ( 24 * 3600 * 30000 ) );</FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
class=3D620214004-31052002>&nbsp;</SPAN>var&nbsp;<SPAN=20
class=3D620214004-31052002>qryString</SPAN>;<BR>&nbsp;var&nbsp;<SPAN=20
class=3D620214004-31052002>myId</SPAN>;<BR>&nbsp;var&nbsp;<SPAN=20
class=3D620214004-31052002>x</SPAN>;<BR>&nbsp;<BR>&nbsp;<SPAN=20
class=3D620214004-31052002>qryString</SPAN> =3D=20
window.location.search;<BR>&nbsp;<SPAN class=3D620214004-31052002>x=20
</SPAN>=3D&nbsp;<SPAN=20
class=3D620214004-31052002>qryString</SPAN>.indexOf("=3D");<BR>&nbsp;<SPA=
N=20
class=3D620214004-31052002>myId</SPAN> =3D&nbsp;<SPAN=20
class=3D620214004-31052002>qryString</SPAN>.substring((<SPAN=20
class=3D620214004-31052002>x</SPAN> + 1),<SPAN=20
class=3D620214004-31052002>qryString</SPAN>.length)</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;function setCookie( name, value=20
){<BR>&nbsp;<SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;var argv =
=3D=20
setCookie.arguments;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;</SPAN>var argc =3D=20
setCookie.arguments.length;<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;var=
 expires=20
=3D (argc &gt; 2) ? argv[2] : null;<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;var=
 Path =3D=20
(argc &gt; 3) ? argv[3] : null;<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;var=
 domain =3D=20
(argc &gt; 4) ? argv[4] : null;<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;var=
 secure =3D=20
(argc &gt; 5) ? argv[5] : false;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN=20
class=3D620214004-31052002> </SPAN>&nbsp;document.cookie =3D name + =
"=3D" + escape=20
(value) +<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp; </SPAN>( ( expires =3D=3D =
null ) ? "" :=20
( "; expires=3D" + expires.toGMTString() ) ) +<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;(=20
( Path =3D=3D null ) ? ""&nbsp;<SPAN =
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;=20
</SPAN>: ( "; path=3D" + Path ) ) +<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;(=20
( domain =3D=3D null ) ? ""&nbsp;: ( "; domain=3D" + domain ) ) =
+<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;(=20
( secure =3D=3D true ) ? "<SPAN =
class=3D620214004-31052002>&nbsp;&nbsp;</SPAN>;=20
secure" : "" );<BR><SPAN=20
class=3D620214004-31052002>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&nbsp;&nbsp;}</=
FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;// Write=20
cookie.<BR>setCookie('QLTReferrer',my<SPAN =
class=3D620214004-31052002>Id</SPAN>,=20
expDate, cookiePath );</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D620214004-31052002><FONT face=3DArial size=3D2>//=20
--&gt;</FONT></SPAN></DIV>
<DIV><SPAN class=3D620214004-31052002><FONT face=3DArial=20
size=3D2>&lt;/script&gt;</FONT></SPAN></DIV></BODY></HTML>

------=_NextPart_000_0003_01C208B2.65F2B140--