Solved

swap images in sequence on refresh

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
My first jQuery plugin: is the right tutorial missing? 2 111
css border raidius issue 7 94
How to silent print from safari browser 6 289
Lines Not Lining Up 2 88
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…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 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