PDA

View Full Version : time specific content



sleipner
05-09-2006, 04:23 PM
I checked here on dynamic drive, jskit, and am right now checking a few other sites that popped up searching Google for free js scripts

anyway, I was wondering if any of you guys have seen or know where I could get a script to make specified time specific content disappear (visibility?) at a certain date - I guess kinda like "if (current date > specified date) {specificID visibility = false;}" (still havent gotten to learning js, so I tried to make it look like ActionScript syntax, since they ought to be close together)

Twey
05-09-2006, 05:46 PM
That's close enough. The first thing to understand is that it's far, far better to do this server-side.
However, if you must do it client-side:
<script type="text/javascript">
var dates = new Array(), // Associative array
now = new Date(),
roughNow = Date.parse(now.getMonths() + "/" + now.getDays() + "/" + now.getFullYear());
dates[0] = "12/25/2004:xmas04";
dates[1] = "06/21/2005:litha05,tsanganniversary";
for(var i=0;dates[i];i++) {
var date = dates[i].substring(0, dates[i].indexOf(":")),
ids = dates[i].substring(":" + 1).split(",");
if(roughNow > Date.parse(date))
for(var j=0;j<ids.length;j++)
if(document.getElementById && document.getElementById(ids[j])) document.getElementById(ids[j]).style.display = "none";
}
</script>That should work. The format for a date entry is mm/dd/yy:id1[, id2 [, ...]]

sleipner
05-09-2006, 06:40 PM
what exactly would be the advantage(s) of doing it server side? if the advantages outweigh the trouble of doing it, could you point me to a site that has it cut-n-paste (or can show me how to do it myself) in ASP

(stuck in miserable Frontpage - I'm feeling the effects of horrible MS formats right now, my boss sends me flyers in Publisher - doesnt even copy over to Word, let alone Frontpage, and barely saves correctly as an html document)

aside from that, I hope this will fit my needs - then I'll just have to explain to my boss that the people browsing the site wont see expired content, it'll just show up in Frontpage/+code

sleipner
05-09-2006, 06:51 PM
something I just realized in the code you gave me - it says
The format for a date entry is mm/dd/yy:id1[, id2 [, ...]] but then the code is
25/12/2004
06/21/2005
so is it dd/mm/yy, or mm/dd/yy?

Twey
05-09-2006, 07:01 PM
Oh! My error, sorry. Edited. It wouldn't actually affect the script (the parser would notice that it was an invalid month and assume dd/mm/yyyy format, I believe) but it keeps things simple. :)


what exactly would be the advantage(s) of doing it server side? if the advantages outweigh the trouble of doing it, could you point me to a site that has it cut-n-paste (or can show me how to do it myself) in ASPUnfortunately not. I don't know any ASP. The advantages would be:
1) "Expired" content wouldn't actually be sent to the user, cutting down on bandwidth usage and keeping your code cleaner
2) No Javascript dependence, and as a result a faster page loading time


stuck in miserable FrontpageHow so?