|
 |
beginning_javascript thread: WHAT'S WRONG IN MY CODE
Message #1 by "sERGEY" <extr_eme@m...> on Wed, 4 Sep 2002 19:27:16
|
|
<HTML>
<HEAD>
<SCRIPT Language="JavaScript">
var LastUpdate=new Date("2011,0,31");
function setCookie (CookieName,CookieValue,CookieExpires,CookiePath){
CookieValue=escape(CookieValue);
if (CookieExpires=="")
{
var NowDate= new Date();
NowDate.setMonth(NowDate.getMonth() +6);
CookieExpires= NowDate.toGMTString();
}
if (CookiePath !="")
{
CookiePath= ";Path=" +CookiePath;
}
document.cookie = CookieName + "=" + CookieValue + ";expires=" +
CookieExpires + CookiePath;
}
function getCookieValue(CookieName){
var CookieValue=document.cookie;
var CookieStartsAt = CookieValue.indexOf(" " + CookieName + "=");
if (CookieStartsAt==-1)
{
CookieStartsAt= CookieValue.indexOf(CookieName + "=");
}
if (CookieStartsAt==-1)
{
CookieValue=null;
}
else
{
CookieStartsAt=CookieValue.indexOf("="+ CookieStartsAt)+1
var CookieEndsAt=CookieValue.indexOf(";",CookieStartsAt);
if (CookieEndsAt==-1)
{
CookieEndsAt=CookieValue.lenght;
}
CookieValue=unescape(CookieValue.substring(CookieStartsAt,CookieEndsAt));
}
return CookieValue;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
var LastVisit = getCookieValue("LastVisit");
if (LastVisit != null)
{
LastVisit = new Date(LastVisit);
if (LastVisit<LastUpdate)
{
document.write("<a href=\"news.html\">");
}
}
var NowDate=new Date();
setCookie("LastVisit",NowDate.toGMTString(),"","")
</SCRIPT>
</BODY>
</HTML>
WHEN I LOADED THIS PAGE MY PAGE DIDN'T REFRESH TO THE PAGE NEWS.HTML!!!
WHAT'S WRONG IN MY CODE???
Message #2 by Jonathan Gold <jonnygee@p...> on Wed, 04 Sep 2002 17:36:30 -0700
|
|
Dunno,
but there's a typo 24 lines from the bottom;
"CookieEndsAt=CookieValue.lenght;"
could that have done it?
Jonathan Gold
jonnygee@p...
-----Original Message-----
From: sERGEY [mailto:extr_eme@m...]
Sent: Wednesday, September 04, 2002 12:27 PM
To: Beginning JavaScript
Subject: [beginning_javascript] WHAT'S WRONG IN MY CODE
<HTML>
<HEAD>
<SCRIPT Language="JavaScript">
var LastUpdate=new Date("2011,0,31");
function setCookie (CookieName,CookieValue,CookieExpires,CookiePath){
CookieValue=escape(CookieValue);
if (CookieExpires=="")
{
var NowDate= new Date();
NowDate.setMonth(NowDate.getMonth() +6);
CookieExpires= NowDate.toGMTString();
}
if (CookiePath !="")
{
CookiePath= ";Path=" +CookiePath;
}
document.cookie = CookieName + "=" + CookieValue + ";expires=" +
CookieExpires + CookiePath;
}
function getCookieValue(CookieName){
var CookieValue=document.cookie;
var CookieStartsAt = CookieValue.indexOf(" " + CookieName + "=");
if (CookieStartsAt==-1)
{
CookieStartsAt= CookieValue.indexOf(CookieName + "=");
}
if (CookieStartsAt==-1)
{
CookieValue=null;
}
else
{
CookieStartsAt=CookieValue.indexOf("="+ CookieStartsAt)+1
var CookieEndsAt=CookieValue.indexOf(";",CookieStartsAt);
if (CookieEndsAt==-1)
{
CookieEndsAt=CookieValue.lenght;
}
CookieValue=unescape(CookieValue.substring(CookieStartsAt,CookieEndsAt));
}
return CookieValue;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
var LastVisit = getCookieValue("LastVisit");
if (LastVisit != null)
{
LastVisit = new Date(LastVisit);
if (LastVisit<LastUpdate)
{
document.write("<a href=\"news.html\">");
}
}
var NowDate=new Date();
setCookie("LastVisit",NowDate.toGMTString(),"","")
</SCRIPT>
</BODY>
</HTML>
WHEN I LOADED THIS PAGE MY PAGE DIDN'T REFRESH TO THE PAGE NEWS.HTML!!!
WHAT'S WRONG IN MY CODE???
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20
|
|
 |