Archive for 14th March 2007

Rotating A Banner On Schedule Via JavaScript / DOM

Recently asked on Yahoo! Answers:

On my website, I want to have a banner box that slowly rotates through 8 or so pictures automatically…?

No mouseover needed, the pictures will slowly swap on their own. I know this is a JavaScript, but don’t know the proper name for this function. Can anyone give me some guidance? All I need is the name of the function, I can look it up from there.

Thanks!!!!

This question should sound somewhat familiar to readers of this blog: We’ve dealt with displaying images based on the current time, randomly displaying an image, displaying an image based on user input and, earlier today, loading images, in order, every time a page is refreshed.

This question, therefore, wouldn’t seem that new. Except that we’re presented with two new challenges: We need not only retain what image to display next, we need to associate a URL with our image, too — so that people can click on the banner and go someplace.

As always, I have a working demo and downloadable code at the end of this discussion.

Continue reading ‘Rotating A Banner On Schedule Via JavaScript / DOM’ »

Loading A Specific Image Sequence On Page Refresh Via JavaScript / DOM

Recently asked on Yahoo! Answers:

Anyone have a Javascript that will allow me to change an image on reload in order and not by random?

I basically need it to change an image when the user clicks reload. The image loaded I dont want to be on a randomizer. I found a code that will basically load a random image on reload. Here it is. I see where the randomizer is but I don’t know how to get it out:

[code snipped]

If I understand this question correctly, what this questioner wants to do is create an ordered list of images — Image 1, Image 2, Image 3, etc. — and display them, in order, with each page refresh.

This question is startlingly similar to the question I answered for displaying an image based on a schedule; in fact, we’ll use a similar approach here. But what this allows us to do is discuss how to use cookies in JavaScript — which is something new and fun.

As always, I’ll have a demo and code you can download at the end of the discussion.

Continue reading ‘Loading A Specific Image Sequence On Page Refresh Via JavaScript / DOM’ »