Solved

swap images in sequence on refresh

Posted on 2014-03-23
4
200 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 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