How do I load a new page each day of the year?

N

nicolai

There are plenty of scripts that load html into a page based on the
day of the week, month, or randomly, but I would like to load a
different page every day of the year.

I would like to give a script a list of 365 html pages and have it
load a new one into that page each day

Thanks in advance
 
D

Darko

There are plenty of scripts that load html into a page based on the
day of the week, month, or randomly, but I would like to load a
different page every day of the year.

I would like to give a script a list of 365 html pages and have it
load a new one into that page each day

Thanks in advance

What did you try yet. Come on, do something we can help you with, it's
not
that we are just waiting here for tasks to do. People can help, but it
shouldn't
be expected they do everything for you.

Cheers
 
N

nicolai

What did you try yet. Come on, do something we can help you with, it's
not
that we are just waiting here for tasks to do. People can help, but it
shouldn't
be expected they do everything for you.

Cheers

Hi Darko,

You don't have to do anything at all and I really don't expect anyone
to do anything. I was just hoping that someone would read this and
know where I can find such a sript, perhaps they were in the same
situation that I'm in. I could have written down all the urls of the
search results I read through, but I didn't think that would help.
 
N

nicolai

(e-mail address removed) said the following on 11/11/2007 10:25 PM:


That will break on Feb 29th every four years.






I doubt you are going to find a ready made script for it. The simplest
way is to name all your files by the date. Use zero based month numbers
as that is what JS uses and it makes it simpler. Use getMonth() to give
you the month number, getDate() to give you the day of the month.

dayOfMonth = new Date().getDate()
monthOfYear = new Date().getMonth()

Now, you can follow Darko's advice. Give it a try, post your best attempt.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Thanks Randy,

I hadn't thought of leap years. I was imagining that it would just
skip the last days of February in those years; which wouldn't matter
to me. Not every page has to be seen every year, the important part is
that a page is not repeated in a year.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
oglegroups.com>, Sun, 11 Nov 2007 15:33:15, (e-mail address removed) posted:
There are plenty of scripts that load html into a page based on the
day of the week, month, or randomly, but I would like to load a
different page every day of the year.

I would like to give a script a list of 365 html pages and have it
load a new one into that page each day

You'll have a problem next year, then.

Name the pages xxx1MMDD.htm, where xxx is anything reasonable, 1 is one,
MM is natural month, DD is day-of-month.

D = new Date()
Name = "xxx" + (10100 + D.getMonth()*100 + D.getDate()) + ".htm"
location.href = Name

Partially tested.
Uses local date.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
B

Bart Van der Donck

I would like to give a script a list of 365 html pages and have it
load a new one into that page each day

function FDoY() { with (this) { // Firefox dislikes D=0
var Y = getFullYear(), M = getMonth(), D = getDate() }
return 1 + (Date.UTC(Y, M, D) - Date.UTC(Y, 0, 1))/864e5 }
Date.prototype.getDoY = FDoY
Date.prototype.setDoY =
new Function("X", "this.setMonth(0, X) ; return this")

document.write("Today is day ",
new Date().getDoY(), " of this year")

http://www.merlyn.demon.co.uk/js-date8.htm#DoY
 
T

Thomas 'PointedEars' Lahn

Randy said:
(e-mail address removed) said the following on 11/11/2007 10:25 PM:

That will break on Feb 29th every four years.

It will break in every leap year, which is not always every four years.


PointedEars
 
G

Gregor Kofler

Thomas 'PointedEars' Lahn meinte:
Randy Webb wrote:

It will break in every leap year, which is not always every four years.

In won't make a difference in real life - given the year of the next
"exception"...

Gregor
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
oglegroups.com>, Mon, 12 Nov 2007 03:59:05, (e-mail address removed) posted:
I hadn't thought of leap years. I was imagining that it would just
skip the last days of February in those years; which wouldn't matter
to me. Not every page has to be seen every year, the important part is
that a page is not repeated in a year.

But it is, presumably, moderately important that the script behaves
without ostensible error on every day of every year, including when
there are 366 of them.

You did not actually say whether or not the same page should be shown on
the same "Gregorian" or ordinal date each year.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
glegroups.com>, Mon, 12 Nov 2007 05:30:33, Bart Van der Donck
function FDoY() { with (this) { // Firefox dislikes D=0
var Y = getFullYear(), M = getMonth(), D = getDate() }
return 1 + (Date.UTC(Y, M, D) - Date.UTC(Y, 0, 1))/864e5 }
Date.prototype.getDoY = FDoY
Date.prototype.setDoY =
new Function("X", "this.setMonth(0, X) ; return this")

document.write("Today is day ",
new Date().getDoY(), " of this year")

http://www.merlyn.demon.co.uk/js-date8.htm#DoY

There's no need to go that route in full for DoY :

function XDoY() { with (new Date()) {
var Y = getFullYear(), M = getMonth(), D = getDate() }
return 1001 + (Date.UTC(Y, M, D) - Date.UTC(Y, 0, 1))/864e5 }

location.href= "xxx" + XDoY() + ".htm"
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Bart Van der Donck said the following on 11/12/2007 8:30 AM:

And I thought I had seen the worst of John's code. I was wrong.

While a neat approach, it won't show the same file on Christmas day
every year.

It will for Orthodox believers.

But that was not a stated requirement.

Christmas, while an essential prerequisite, is of course of secondary
importance. One could do a revision to give the same file on Easter
Sunday every year.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top