Solved

alternate between 3+ urls every 2 minutes

Posted on 2013-06-04
2
159 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now