Closed Thread Icon

Preserved Topic: "Last Visit" Problem Pages that link to <a href="https://ozoneasylum.com/backlink?for=17748" title="Pages that link to Preserved Topic: &amp;quot;Last Visit&amp;quot; Problem" rel="nofollow" >Preserved Topic: &quot;Last Visit&quot; Problem\

 
Author Thread
Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 05-30-2000 01:19

So, I'm trying to update my What's New page and I'd like to add a simple "You were last here on..." statement to give people a reference point for the list of updates. I found a script (below) that seems to do exactly what I want, except for one problem. In Netscape, it works fine. But, in IE4 the year comes out "3900." I finally broke down and got a book to start teaching myself Javascript, but I still don't know enough to figure out what the problem is here. Any help is much appreciated!<P><SCRIPT LANGUAGE="JavaScript">
<!--
function getCookieValue(varname) {
varname += "=";
startpos = document.cookie.indexOf(varname);
if (startpos >= 0) {
startpos += varname.length;
endpos = document.cookie.indexOf(";", startpos);
if (endpos == -1) endpos = document.cookie.length;
return document.cookie.substring(startpos, endpos);
}
}<P>var todaydate = new Date();
var visitdate = new Date();
var lastvisit = getCookieValue("lastvisit");<P>if (lastvisit == null) {
lastvisit = 0;
visitdate.setTime(0);
//alert("Welcome to this page!")
document.write("Please check back often for updates!");
} else {
visitdate.setTime(lastvisit);
var monthstr = "JanFebMarAprMayJunJulAugSepOctNovDec";
var date = visitdate.getDate();
var monthint = visitdate.getMonth() * 3;
var month = monthstr.substring(monthint, monthint + 3);
var year = visitdate.getYear() + 1900;
//alert("Last visit: " + date + " " + month + " " + year);
document.write("Your last visit to What's New was on " + month + " " + date + ", " + year + ".");
}
var today = todaydate.getTime();
// check for at least 1 hour elapsing before updating
if ((today - lastvisit) > 3600000) {
var expires = new Date();
// set expiry to 180 days
expires.setTime(today + 15552000000);
document.cookie = "lastvisit=" + today + "; expires=" +
expires.toGMTString();
}
// -->
</SCRIPT><P>

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-30-2000 03:15

The dateobj.getYear() function works differently on IE and NN, and it's a very buggy function. Instead, use the dateobj.getFullYear() function, which works correctly on both browsers. And you won't have to add 1900 to the result, either.<P> <IMG SRC="http://www.angelfire.com/ma2/slimesareneat2/images/slimesig.gif">

Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 05-30-2000 18:46

I'll try that, thanks.<P>

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-09-2000 20:25

Wes - did the suggested fix work? If so, can you post the correct code?

Pat Richard
Web weenie

Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 06-09-2000 20:34

Oh, yes it did. The corrected code is as follows:

<SCRIPT LANGUAGE="JavaScript">

<!--
function getCookieValue(varname) {
varname += "=";
startpos = document.cookie.indexOf(varname);
if (startpos >= 0) {
startpos += varname.length;
endpos = document.cookie.indexOf(";", startpos);
if (endpos == -1) endpos = document.cookie.length;
return document.cookie.substring(startpos, endpos);
}
}

var todaydate = new Date();
var visitdate = new Date();
var lastvisit = getCookieValue("lastvisit");

if (lastvisit == null) {
lastvisit = 0;
visitdate.setTime(0);
document.write("This your first time to visit this page.");
} else {
visitdate.setTime(lastvisit);
var monthstr = "JanFebMarAprMayJunJulAugSepOctNovDec";
var date = visitdate.getDate();
var monthint = visitdate.getMonth() * 3;
var month = monthstr.substring(monthint, monthint + 3);
var year = visitdate.getFullYear();
document.write("Your last visit to this page was on " + month + " " + date + ", " + year + ".</SPAN>");
}
var today = todaydate.getTime();
// check for at least 1 hour elapsing before updating
if ((today - lastvisit) > 3600000) {
var expires = new Date();
// set expiry to 180 days
expires.setTime(today + 15552000000);
document.cookie = "lastvisit=" + today + "; expires=" +
expires.toGMTString();
}
// -->

</SCRIPT>

« BackwardsOnwards »

Show Forum Drop Down Menu