Solved

alternate between 3+ urls every 2 minutes

Posted on 2013-06-04
2
169 Views
Last Modified: 2013-06-23
Hiya All

I have a need to have a page that shows a one of 3+ urls every 2 minutes.

I don't mind using iframe or having some javascript that manages the whole thing.

Ww
0
Comment
Question by:willa666
2 Comments
 
LVL 9

Expert Comment

by:TvMpt
ID: 39220553
Hi.
This code do what you want but needs a small changes

var d = new Date();
var t = d.getTime();
var days = Math.floor(t / (86400000));

2) put your images in an array

var imagearray = new Array('image1.jpg','image2.jpg'...);

3) use the MOD operator (%) to find the remainder when you divide days by the number of images in the array.

var i = days % imagearray.length;

4) then show the image corresponding to that value.

var img = new Image();
img.src = imagearray[i]; 

Open in new window


Just use an url array instead img's and instead 24h (86400000ms) use 3m ( 90000 )
0
 
LVL 18

Accepted Solution

by:
nap0leon earned 500 total points
ID: 39222098
The desired behavior is slightly unclear to me...

Should the page change what a user is seeing while they are on the page?
or
Should the page show URL1 and two minutes later, if I refresh the page, show URL2, etc.?
or
From 8:00-8:02 show URL1 to everyone.  
From 8:02-8:04, show URL2 to everyone.
From 8:04-8:06, show URL3 to everyone.

If you want to rotate what the user sees while they are on the page, like a rotating banner, all you need is a timer that changes the "src" attribute of your iframe every 2 minutes.

The attached HTML page rotates three URLs every 5000 milliseconds.  Change the URLs to be the pages/images you want displayed.  Change the height and width of the iFrame to match the contents you are showing.  Change the timer interval to 2 minutes (120000 milliseconds) when you are done testing.

(if you are actually rotating images, then you don't need an iframe, you can update the src attribute of the image on your page)
Q-28147461.html
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

829 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