Solved

swap images in sequence on refresh

Posted on 2014-03-23
4
191 Views
Last Modified: 2014-03-24
I have made a website template with a header image.  I would like the image to change upon refresh/reload. I have a file in which I will keep a series of images to fill the template placeholder: images/swap/image1.jpg, image2.jpg, etc. Here is a webpages. Everything has been uploaded. http://mcleantreesfoundation.org/index1.html

You will see that I have a javascript file in the template that was supposed to swap the image. It isn't working.

I would be very grateful for a simple solution. I don't know jscript, javascript, or php, but I can follow simple directions. Thank you.
0
Comment
Question by:Biker5
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39949080
In swap.js, change this:
var oldWindowOnload=window.onload;

Open in new window

to this:
var oldWindowOnload=window.onload||function(){};

Open in new window


HTH,
Dan
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 500 total points
ID: 39949683
Your swap script is stopping execution because it is trying to execute a function which does not exist. There were also a couple of other errors in it (lines 26 to 41)). in your swap.js change it to:
window.onload=function() {
		if (oldWindowOnload) oldWindowOnload();
		var header = document.getElementById('header');
		if (!header) return false;
		var headerImgTags = header.getElementsByTagName('IMG');
		if (!headerImgTags || headerImgTags.length<1) return false;
		var headerImgIdx = readCookie("headerImageIndex");
		if (!headerImgIdx) {headerImgIdx=0; } else { headerImgIdx++; }
		if (headerImgIdx > (headerImages.length-1)) headerImgIdx=0;
		createCookie('headerImageIndex',headerImgIdx,1);
		headerImgTags[0].src=headerImages[headerImgIdx];
	} 

Open in new window

0
 

Author Closing Comment

by:Biker5
ID: 39950240
I changed the code as indicated and it all works perfectly!!! Thank you so much.
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39950298
Glad to help. Good luck.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now