[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

swap images in sequence on refresh

Posted on 2014-03-23
4
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
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.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

649 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