Solved

Updated since last visit

Posted on 1998-12-21
20
260 Views
Last Modified: 2010-04-09
I saw 1 site that was topic What's updated since your last visit. How to do it (i think it's Javascript)
0
Comment
Question by:jack_p50
  • 12
  • 7
20 Comments
 
LVL 11

Expert Comment

by:mouatts
ID: 1840894
The chances are that it isn't done by javascript but by the server. When you connect to this site they will be sending you a cookie that will contain todays date. When you next connect this cookie is sent back to them and the server simply has to look in its database of changes for those implemented since the date in the cookie.

Steve
0
 
LVL 4

Expert Comment

by:martinag
ID: 1840895
I think mouatts is right. It could be done by JavaScript, but server-side would be so much easier.

Martin
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840896
That's very good, but how to do this?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:martinag
ID: 1840897
Is this ok?

<HTML>
<HEAD>
<TITLE>What's new?</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Initialization
lastVisit = getCookie("Last visit");
if (lastVisit == null) lastVisit = 0;
today = new Date();
setCookie("Last visit", today.getTime());
descriptions = new Array();
dates = new Array();

// List all updates
// To get the integer that you should use, open up Netscape and write
// mocha:getCode()
addUpdate("Bug fixes", 914280388850)
addUpdate("Minor improvements", 914280529020)

// Function declarations
function updates() {
  s = "";
  for (i=0;i<dates.length;i++) {
    if (dates[i] > lastVisit) {
      s += "<B>" + new Date(dates[i]) + "</B><BR>" + descriptions[i] + "<P>";
    }
  }
  if (s == "")
    return "Nothing has happened around here since the last time you were here.";
  else
    return "This has happened since your last visit:<P>" + s;
}
function setCookie(name, value, expire) {
  document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : (";expires=" + expire.toGMTString()));
}
function getCookie(Name) {
  var search = Name + "=";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1)
        end = document.cookie.length;
      return unescape(document.cookie.substring(offset, end));
    }
  }
}
function addUpdate(description, date) {
  descriptions[descriptions.length] = description;
  dates[dates.length] = date;
}
function getCode() {
  d = new Date();
  prompt("Here's the code:", 'addUpdate("...", ' + d.getTime() + ')');
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
  document.write(updates());
// -->
</SCRIPT>
</BODY>
</HTML>

I can write a date format routine to get it look more "professional". Just tell me how you want it to look.

Martin
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840898
Ok, please do it and send as answer. Exactly I want :
1)User came to site and visit all updates
2)He comes again and visits "Since your last visit, was updated ....."(list of updates as you did).
3)Please, do such thing that if user wants, he can see all updates (i.e. some button "see all updates")
4)Big thanx  ;)
0
 
LVL 4

Expert Comment

by:martinag
ID: 1840899
I'm no good at date formats, but this is how I've made it: "Tuesday 22 Dec, 18:09" Let me know if it's wrong and I'll change it.

<HTML>
<HEAD>
<TITLE>What's new?</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Initialization
last = getCookie("Last visit");
if (last == null) last = "0";
lastVisit = parseInt(last);
lastVisit *= 1000;

today = new Date();
expdate = new Date();
expdate.setTime(expdate.getTime() + 30*24*60*60*1000);
setCookie("Last visit", today.getTime()/1000, expdate);
descriptions = new Array();
dates = new Array();

// List all updates
// To get the code that you should use, open up Netscape and write
// mocha:getCode()
// In the location field
addUpdate("Bug fixes", 914280388850);
addUpdate("Minor improvements", 914280529020);
addUpdate("Date formatting and allUpdates() function", 914342950000);

// Function declarations
function allUpdates() {
  if (dates.length == 0)
    code = "The list of updates is currently empty.";
  else {
    code = "<TITLE>All updates</TITLE>";
    for (i=0;i<dates.length;i++)
      code += "<B>" + formatDate(dates[i]) + "</B><BR>" + descriptions[i] + "<P>";
    code += "<P><HR>There have been <B>" + dates.length + "</B> updates.";
  }
  w = open('','','height=300,width=300,scrollbars');
  w.document.open();
  w.document.write(code);
  w.document.close();
}
function updates() {
  s = "";
  for (i=0;i<dates.length;i++) {
    if (dates[i] > lastVisit)
      s += "<B>" + formatDate(dates[i]) + "</B><BR>" + descriptions[i] + "<P>";
  }
  if (s == "")
    return "Nothing has happened around here since the last time you were here.";
  else
    return "This has happened since your last visit:<P>" + s;
}
function setCookie(name, value, expire) {
  document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : (";expires=" + expire.toGMTString()));
}
function getCookie(Name) {
  var search = Name + "=";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1)
        end = document.cookie.length;
      return unescape(document.cookie.substring(offset, end));
    }
  }
}
function addUpdate(description, date) {
  descriptions[descriptions.length] = description;
  dates[dates.length] = date;
}
function getCode() {
  d = new Date();
  prompt("Here's the code:", 'addUpdate("...", ' + d.getTime() + ')');
}
function formatDate(date) {
  d = new Date(date);
  // hh:mm
  h = d.getHours();
  m = d.getMinutes();
  time = ((h<10) ? "0"+h : h) + ":" + ((m<10) ? "0"+m : m);
  // month
  months = new Array(12);
  months[0] = "Jan"; months[1]  = "Feb"; months[2]  = "Mar";
  months[3] = "Apr"; months[4]  = "May"; months[5]  = "Jun";
  months[6] = "Jul"; months[7]  = "Aug"; months[8]  = "Sep";
  months[9] = "Oct"; months[10] = "Nov"; months[11] = "Dec";
  month = months[d.getMonth()];
  // weekday
  days = new Array(7);
  days[0] = "Sun"; days[1] = "Mon"; days[2] = "Tues"; days[3] = "Wednes";
  days[4] = "Thurs"; days[5] = "Fri"; days[6] = "Satur";
  weekday = days[d.getDay()] + "day";
  return weekday + " " + d.getDate() + " " + month + ", " + time;
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
  document.write(updates());
  document.write('<FORM><INPUT TYPE="BUTTON" VALUE="All updates" onClick="allUpdates()"></FORM>');
// -->
</SCRIPT>
</BODY>
</HTML>

Martin
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840900
WoW!
Here are last questions :
1)Please do in so format : "22th of December, 1998 :
                                         ..............."
2)Please do when user presses all updates it reloads to current window.
3)Next time post it as answer

Thanx
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840901
and please, in "there were ... updates" add "since 2 december, 1998"(i.e.)
0
 
LVL 4

Expert Comment

by:martinag
ID: 1840902
<HTML>
<HEAD>
<TITLE>What's new?</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Initialization
last = getCookie("Last visit");
if (last == null) last = "0";
lastVisit = parseInt(last);
lastVisit *= 1000;

today = new Date();
expdate = new Date();
expdate.setTime(expdate.getTime() + 30*24*60*60*1000);
setCookie("Last visit", today.getTime()/1000, expdate);
descriptions = new Array();
dates = new Array();

// List all updates
// To get the code that you should use, open up Netscape and write
// mocha:getCode()
// In the location field
addUpdate("Bug fixes", 914280388850);
addUpdate("Minor improvements", 914280529020);
addUpdate("Date formatting and allUpdates() function", 914342950000);

// Function declarations
function allUpdates() {
  if (dates.length == 0)
    code = "The list of updates is currently empty.";
  else {
    code = "<TITLE>All updates</TITLE>";
    for (i=0;i<dates.length;i++)
      code += "<B>" + formatDate(dates[i]) + "</B><BR>" + descriptions[i] + "<P>";
    code += "<P><HR>There have been <B>" + dates.length + "</B> updates since " + formatDate(dates[0]) + ".";
  }
  location.href = "write.htm?" + escape(code);
}
function updates() {
  s = "";
  for (i=0;i<dates.length;i++) {
    if (dates[i] > lastVisit)
      s += "<B>" + formatDate(dates[i]) + "</B><BR>" + descriptions[i] + "<P>";
  }
  if (s == "")
    return "Nothing has happened around here since the last time you were here.";
  else
    return "This has happened since your last visit:<P>" + s;
}
function setCookie(name, value, expire) {
  document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : (";expires=" + expire.toGMTString()));
}
function getCookie(Name) {
  var search = Name + "=";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1)
        end = document.cookie.length;
      return unescape(document.cookie.substring(offset, end));
    }
  }
}
function addUpdate(description, date) {
  descriptions[descriptions.length] = description;
  dates[dates.length] = date;
}
function getCode() {
  d = new Date();
  prompt("Here's the code:", 'addUpdate("...", ' + d.getTime() + ')');
}
function formatDate(date) {
  d = new Date(date);
  // hh:mm
  h = d.getHours();
  m = d.getMinutes();
  time = ((h<10) ? "0"+h : h) + ":" + ((m<10) ? "0"+m : m);
  // month
  months = new Array(12);
  months[0] = "January"; months[1]  = "February"; months[2]  = "March";
  months[3] = "April"; months[4]  = "May"; months[5]  = "June";
  months[6] = "July"; months[7]  = "August"; months[8]  = "September";
  months[9] = "October"; months[10] = "November"; months[11] = "December";
  month = months[d.getMonth()];
  // day
  day = d.getDate() + "";
  last = day.substring(day.length-1);
  if (last == "1") day += "st";
  else if (last == "2") day += "nd";
  else if (last == "3") day += "rd";
  else day += "th";
  return day + " of " + month + ", " + (d.getYear()+1900);
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
  document.write(updates());
  document.write('<FORM><INPUT TYPE="BUTTON" VALUE="All updates" onClick="allUpdates()"></FORM>');
// -->
</SCRIPT>
</BODY>
</HTML>

You will also need write.htm:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
if (location.search && location.search.length > 0)
  document.write(unescape(location.search.substring(1)));
// -->
</SCRIPT>
</HEAD>
</HTML>

Merry Christmas, Martin
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840903
Very sorry, but I have forgotten one thing :
1)what's mocha:getcode() and how to use it (nothing happens when I write it in location)
2)how to calculate update's time (in addupdate() )
3)can you please do it to look as that page : "www.geocities.com/TimesSquare/Portal/9206/news.html"
4)when I press allupdates button, all is ok, but there's very many **** in location bar.
I appreciate your great efforts for so few points - sorry, I'm lack of them
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840904
Can allupdates be done without write.htm?
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840905
Please, do it, I pray that it's last thing that I ask about it - I'll accept your next answer.
BIG thanx to you.
0
 
LVL 4

Expert Comment

by:martinag
ID: 1840906
1) what's mocha:getcode() and how to use it (nothing happens when I write it in location)
Are you using Netscape? BTW, it should be
  mocha:getCode()

2)how to calculate update's time (in addupdate())
  mocha:getCode()
will give you the code to copy and paste it in.

3)can you please do it to look as that page: "www.geocities.com/TimesSquare/Portal/9206/news.html
Here are the two functions that are changed:
function allUpdates() {
  if (dates.length == 0)
    code = "The list of updates is currently empty.";
  else {
    code = "<TITLE>All updates</TITLE>";
    for (i=0;i<dates.length;i++)
      code += "<H3>Update at " + formatDate(dates[i]) + " :</H3>\n<BLOCKQUOTE>" + descriptions[i] + "\n</BLOCKQUOTE>";
    code += "<P><HR>There have been <B>" + dates.length + "</B> updates since " + formatDate(dates[0]) + ".";
  }
  location.href = "write.htm?" + escape(code);
}
function updates() {
  s = "";
  for (i=0;i<dates.length;i++) {
    if (dates[i] > lastVisit)
      s += "<H3>Update at " + formatDate(dates[i]) + " :</H3>\n<BLOCKQUOTE>" + descriptions[i] + "\n</BLOCKQUOTE>";
  }
  if (s == "")
    return "Nothing has happened around here since the last time you were here.";
  else
    return "This has happened since your last visit:<P><CODE>" + s + "<P></CODE>";
}

4)when I press allupdates button, all is ok, but there's very many **** in location bar.
Can allupdates be done without write.htm?
It can be done in another way, but then you'll have to use cookies. Since cookies can be turned of there's a risk that nothing will show up. Do you want me to implement them anyway (if they don't accept them it's their problem, right?:-))?
There will still be a redirection to another page (not neccesarily write.htm, it could be allupdates.htm or something like that).

Merry Christmas, Martin
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840907
Ok, but I still don't know how to use mocha:getCode() (it doesn't does nothing)
Can you give me example of using it?
Btw, I use Netscape 4.5
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840908
Also, please add <code> to place where <blockquote> is.
Can you PLEASE do so that it would be almost identical to my page.
Big thanx to you, you're great guy to deal with!
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840909
Ok, mocha:getCode() works, but does it return current time? Can it return any time (i.e. mocha:getCode(22,12,1998) which stands for 22th of December, 1998). Thanx one more time.
0
 
LVL 4

Expert Comment

by:martinag
ID: 1840910
It looks just like your home page already.

Here's the new getCode():
function getCode(d, m, y) {
  if (y && y < 1900) y += 1900;
  k = new Date();
  params = (y ? y : k.getYear()) + ',' + (m ? m-1 : k.getMonth()) + ',' + (d ? d : k.getDate());
  eval("a = new Date(" + params + ")");
  prompt("Here's the code:", 'addUpdate("...", ' + a.getTime() + ')');
}

Martin
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840911
Ok, I'm satisfied. Thanx and answer this q
0
 
LVL 4

Accepted Solution

by:
martinag earned 30 total points
ID: 1840912
Answer.

Martin
0
 
LVL 4

Author Comment

by:jack_p50
ID: 1840913
At last it's done just superb
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question