[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Updated since last visit

I saw 1 site that was topic What's updated since your last visit. How to do it (i think it's Javascript)
0
jack_p50
Asked:
jack_p50
  • 12
  • 7
1 Solution
 
mouattsCommented:
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
 
martinagCommented:
I think mouatts is right. It could be done by JavaScript, but server-side would be so much easier.

Martin
0
 
jack_p50Author Commented:
That's very good, but how to do this?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
martinagCommented:
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
 
jack_p50Author Commented:
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
 
martinagCommented:
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
 
jack_p50Author Commented:
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
 
jack_p50Author Commented:
and please, in "there were ... updates" add "since 2 december, 1998"(i.e.)
0
 
martinagCommented:
<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
 
jack_p50Author Commented:
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
 
jack_p50Author Commented:
Can allupdates be done without write.htm?
0
 
jack_p50Author Commented:
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
 
martinagCommented:
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
 
jack_p50Author Commented:
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
 
jack_p50Author Commented:
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
 
jack_p50Author Commented:
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
 
martinagCommented:
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
 
jack_p50Author Commented:
Ok, I'm satisfied. Thanx and answer this q
0
 
martinagCommented:
Answer.

Martin
0
 
jack_p50Author Commented:
At last it's done just superb
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 12
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now