Solved

swap images in sequence on refresh

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

839 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