Setting Webpages to alter at a set time
Setting Webpages to alter at a set time
Author
Discussion

AL666

Original Poster:

2,679 posts

249 months

Monday 9th April 2007
quotequote all
Hello everyone, I'm rubbish with javascript, but I'm trying to learn it at the moment... I was wondering if anybody knew how you set something to change at a particular time of day.

What I'm after is a coloured circle on a page that will change colour at particular times of the day and will link to another website that will display news topics every 20 minutes, so basically the circle will change colour when a new story is released, it will be used as a way of alerting people to a news story by using colours, but this is just for testing purposes.

Any help would be great, and if you think that I should use something other than js, please say.


Cheers,

AL

J_S_G

6,177 posts

281 months

Tuesday 10th April 2007
quotequote all
Guess the real question is:
1. Do you want it to change every 20 minutes regardless? OR
2. Do you want it to change when there's a new news-story

(1) is trivial with a bit of JavaScript. Or a bit of server-side code (ASP/PHP/etc)
(2) will need some (most realistically server-side) code to read the target page and check for changes before serving up a web-page to the user to let them know about changes.

More detail?

AL666

Original Poster:

2,679 posts

249 months

Tuesday 10th April 2007
quotequote all
I want it to change every twenty minutes, regardless. As it's only going to be used for psycological testing of a remote study group. What code would I need to use to make it happen in js, or php (it's been a while since I used php)

Thanks a lot for your reply



AL

size13

2,033 posts

288 months

Tuesday 10th April 2007
quotequote all
You need to use

<meta http-equiv="refresh" content="1200" />

in the <head> section of your page

AL666

Original Poster:

2,679 posts

249 months

Tuesday 10th April 2007
quotequote all
OK, well, the thing is, I want the circle to change colour every twenty minutes, so it'll be orange, then change to blue every twenty minutes for 5 minutes...

So it'll be blue orange for 15 minutes, then blue for 5, then orange for 15... etc.

And the circle will link to a news page which I'll be updating every twenty minutes, so the person viewing the page with the circle on will see it change to blue and then be able to view the new news story only when the circle's changed to blue... Will the code that you've given me do anyhting like that, or is it just set to refresh the page every twenty minutes from when the user's opened it?

Cheers again, and I'm sorry for dragging this out angel



AL

Plotloss

67,280 posts

301 months

Tuesday 10th April 2007
quotequote all
The meta refresh will reload the whole page

Its sounding like you're going to have to resort to AJAX, I may be way off the mark though.

Size Nine Elm

5,167 posts

315 months

Tuesday 10th April 2007
quotequote all
You could create a GIF with coloured circles and a very long frame change rate...

Either that or just preload several images, and cycle them on a timer.

dilbert

7,741 posts

262 months

Tuesday 10th April 2007
quotequote all
This scheme is all well and good. Has nobody noticed that if your browser navigates away from the page and then comes back to it, the user is going to go back to the beginning of the colour sequence.

If they only look at the page for a minute, then they'll only evr see the same colour.

morningside

24,147 posts

260 months

Tuesday 10th April 2007
quotequote all
Why not have two or three etc pages


=======blue.html======
<HTML>
<HEAD>
<TITLE>Title of your page</TITLE>
<body bgcolor="blue">
<meta http-equiv="Refresh" content="5; url=orange.html">
</HEAD>
<BODY>
</BODY>
I am blue for 5 seconds
</HTML>


======orange.html======
<HTML>
<HEAD>
<TITLE>Title of your page</TITLE>
<body bgcolor="orange">
<meta http-equiv="Refresh" content="15; url=blue.html">
</HEAD>
<BODY>
</BODY>
I am orange for 15 seconds
</HTML>


Same refresh code as above but after a pre-set time it changes the .HTML page - in this case a background of either blue/orange.


Edited by morningside on Tuesday 10th April 19:25

AL666

Original Poster:

2,679 posts

249 months

Wednesday 11th April 2007
quotequote all
That's a good idea, thanks, but I was thinking more along the lines of the js reading the user's system clock, because as this is remote and I want to try it with more than one person at a time, it's probably best that they're all running at the same time, in case somebody doesn't open the site until 4 or 5 minutes into the test.... Then their site would be behind everyone else's.


Cheers again for all the help,



AL

AL666

Original Poster:

2,679 posts

249 months

Wednesday 11th April 2007
quotequote all
Actually, just thinking about it.... Couldn't I set the webpage (with the circle on) to refresh every 20 seconds and then when I upload a news story, I can also upload the page with the circle on, again, but with a different-coloured circle...

Would that work?

dilbert

7,741 posts

262 months

Wednesday 11th April 2007
quotequote all
I'm sure there are many ways to do this, but if you have CGI, just serve up a page from on the server which is dynamically generated on the basis of system time at the server.

If you can run an application on the server, just write an app which regenerates a page on the server every 20mins. That way you don't even need CGI. Just put an html refresh into the page.

TheExcession

11,669 posts

281 months

Wednesday 11th April 2007
quotequote all
Read about AJAX - it's JavaScript that allows you to 'silently/transparently/without-the-user-knowing' contact the server and ask for a URL without reloading the whole page again.

When the contents of the URL are returned you can insert them into a DIV or modify any other page element that you can address from JavaScript (i.e. anything and everything).

If you combine AJAX with a bit of PHP and SQL then you start to be able to create some extremely cool/slick/powerful web applications.

For example (and very simply put - the app is considerably more complex than this), I'm working on a Web App that retrieves live information from a database. I run an AJAX call to a PHP page every few seconds, the PHP queries the DB to find out if any new events are present in the DB. If there are new events the DB returns the HTML to present the new events. This HTML is then added to the innerHTML of an existing DIV.

The user never sees a page refresh, yet the content of the page in front of them is changing as and when new information is available.

HTH
best
Ex

J_S_G

6,177 posts

281 months

Friday 13th April 2007
quotequote all
TheExcession said:
Read about AJAX - it's JavaScript that allows you to 'silently/transparently/without-the-user-knowing' contact the server and ask for a URL without reloading the whole page again.

...

That's an exceptionally complicated way of achieving this!

J_S_G

6,177 posts

281 months

Friday 13th April 2007
quotequote all
AL666 said:
Actually, just thinking about it.... Couldn't I set the webpage (with the circle on) to refresh every 20 seconds and then when I upload a news story, I can also upload the page with the circle on, again, but with a different-coloured circle...

Would that work?

Yes, if combined with a meta-refresh say every minute or so.

Make sure you change the HTML to point to a new GIF file rather than switching the image, or there's a chance it'll cache the old one.

AL666

Original Poster:

2,679 posts

249 months

Saturday 14th April 2007
quotequote all
J_S_G said:
AL666 said:
Actually, just thinking about it.... Couldn't I set the webpage (with the circle on) to refresh every 20 seconds and then when I upload a news story, I can also upload the page with the circle on, again, but with a different-coloured circle...

Would that work?

Yes, if combined with a meta-refresh say every minute or so.

Make sure you change the HTML to point to a new GIF file rather than switching the image, or there's a chance it'll cache the old one.


Thanks, that's what I wanted to hear, will the refreshing every minute make the screen visibly refresh, or will it only change if I alter the content?

Cheers again,

AL

J_S_G

6,177 posts

281 months

Saturday 14th April 2007
quotequote all
AL666 said:
J_S_G said:
AL666 said:
Actually, just thinking about it.... Couldn't I set the webpage (with the circle on) to refresh every 20 seconds and then when I upload a news story, I can also upload the page with the circle on, again, but with a different-coloured circle...

Would that work?

Yes, if combined with a meta-refresh say every minute or so.

Make sure you change the HTML to point to a new GIF file rather than switching the image, or there's a chance it'll cache the old one.


Thanks, that's what I wanted to hear, will the refreshing every minute make the screen visibly refresh, or will it only change if I alter the content?

In IE6, it'll "flicker" very quickly (assuming they're on broadband). In Firefox it shouldn't. Can't remember in IE7.

TheExcession

11,669 posts

281 months

Saturday 21st April 2007
quotequote all
J_S_G said:
TheExcession said:
Read about AJAX - it's JavaScript that allows you to 'silently/transparently/without-the-user-knowing' contact the server and ask for a URL without reloading the whole page again.

...

That's an exceptionally complicated way of achieving this!

I wouldn't say it's complicated, I'd suggest it is the correct way to do it.
With Java Script you can change the URL of the image to be downloaded, stick that as the inner HTML of a DIV and Bob's your unlce's monkey.

It has a lot of benefits, primarily that the whole page doesn't get reloaded. Additionally the OP said that he was trying to learn JavaScript. It took me about 10 minutes to get AJAX working on some of my pages, to the degree where by I'll be using this technology as often as possible. Once you get the example code working, it's piece of piss.

Just my opinion of course.

AL666

Original Poster:

2,679 posts

249 months

Sunday 22nd April 2007
quotequote all
Hey, thanks for the new reply. I solved this simply, for testing, by creating a page with a blue circle on with a meta-refresh of 5 seconds. Then when I wanted to let the user see a new news story I set the page to redirect to one of 15 pages with a different-coloured pulsing circle on, which then let the user click on it to be sent to the location of the news story.
I set a redirect time of 3 minutes on the page with the pulsing circle on and set the news story to open in a new tab, so when the user had finished reading the story and closed it, the pulsing circle would still be there for a temporary time and would then redirect to the index (blue circle), thus making the story inaccessible again (unless they decided to work our the URLs, which wasn't a problem).


Cheers again, all is well,


AL

option click

1,178 posts

257 months

Sunday 22nd April 2007
quotequote all
AL666 said:
Hey, thanks for the new reply. I solved this simply, for testing, by creating a page with a blue circle on with a meta-refresh of 5 seconds. Then when I wanted to let the user see a new news story I set the page to redirect to one of 15 pages with a different-coloured pulsing circle on, which then let the user click on it to be sent to the location of the news story.
I set a redirect time of 3 minutes on the page with the pulsing circle on and set the news story to open in a new tab, so when the user had finished reading the story and closed it, the pulsing circle would still be there for a temporary time and would then redirect to the index (blue circle), thus making the story inaccessible again (unless they decided to work our the URLs, which wasn't a problem).


Cheers again, all is well,


AL


Glad you've sorted it, but are you really sure you want to do this - firing users off to different pages that they havent requested is hardly good usability. Surely better to use the pulsing circle device to highlight new content and encourage the user to click through, rather than dictate their journey?