Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Updated since last visit

Posted on 1998-12-21
20
Medium Priority
?
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 120 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

618 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