View Full Version : random url in iframe with timer?
SwordOfWar
06-02-2008, 04:06 AM
I am using the following script in my header tag to display rotated urls in an iframe but I would like this to be random rather than in a particular order but also retaining the ability to have urls rotated every number of seconds or so like my current script does. If someone could help suggest any modification to the below code to do this then it would be greatly helpful. Thanks.
<script type="text/javascript">
var pages=new Array();
pages[0]="http://www.link1.com";
pages[1]="http://www.link2.com";
pages[2]="http://www.link3.com";
pages[3]="http://www.link4.com";
var i=0;
var time=7000; // this is set in milliseconds
function pageChange() {
document.getElementById("frame").src=pages[i];
i++;
if(i==pages.length) {
i=0;
}
setTimeout("pageChange()",time);
}
onload=pageChange;
</script>
rangana
06-02-2008, 05:56 AM
See if this helps:
<script type="text/javascript">
var pages=new Array();
pages[0]="http://www.link1.com";
pages[1]="http://www.link2.com";
pages[2]="http://www.link3.com";
pages[3]="http://www.link4.com";
var time=7000; // this is set in milliseconds
function pageChange() {
var rand=Math.floor(Math.random()*pages.length);
document.getElementById("frame").src=pages[rand];
setTimeout("pageChange()",time);
}
onload=pageChange;
</script>
pankajt
06-02-2008, 06:09 PM
Can anybody suggests how to do above per hour...like evry hour at starting the page changes and remains there till next hour.....
P.S. I don't want to get it changed on every reload.....
Can anybody help me on this??
Regards
pankajt
SwordOfWar
06-02-2008, 10:21 PM
Can anybody suggests how to do above per hour...like evry hour at starting the page changes and remains there till next hour.....
P.S. I don't want to get it changed on every reload.....
Can anybody help me on this??
Regards
pankajt
I think you need something like PHP to do that.
Thanks for the above script! It works perfectly =p
jscheuer1
06-03-2008, 06:20 AM
Can anybody suggests how to do above per hour...like evry hour at starting the page changes and remains there till next hour.....
P.S. I don't want to get it changed on every reload.....
Can anybody help me on this??
Regards
pankajt
If you have exactly 24 pages:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<iframe name="hourFrame" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
<script type="text/javascript" defer="defer">
;(function(){
if ( !window.frames || !window.location.replace ) return;
var pages = [];
pages[0] = 'http://www.link1.com';
pages[1] = 'http://www.link2.com';
pages[2] = 'http://www.link3.com';
pages[3] = 'http://www.link4.com';
pages[4] = 'http://www.link5.com';
pages[5] = 'http://www.link6.com';
pages[6] = 'http://www.link7.com';
pages[7] = 'http://www.link8.com';
pages[8] = 'http://www.link9.com';
pages[9] = 'http://www.link10.com';
pages[10] = 'http://www.link11.com';
pages[11] = 'http://www.link12.com';
pages[12] = 'http://www.link13.com';
pages[13] = 'http://www.link14.com';
pages[14] = 'http://www.link15.com';
pages[15] = 'http://www.link16.com';
pages[16] = 'http://www.link17.com';
pages[17] = 'http://www.link18.com';
pages[18] = 'http://www.link19.com';
pages[19] = 'http://www.link20.com';
pages[20] = 'http://www.link21.com';
pages[21] = 'http://www.link22.com';
pages[22] = 'http://www.link23.com';
pages[23] = 'http://www.link24.com';
window.frames['hourFrame'].location.replace( pages[new Date().getUTCHours()] );
})();
</script>
</body>
</html>
jscheuer1
06-03-2008, 12:23 PM
Or, for virtually any number of pages, one page per hour:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<iframe name="hourFrame" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
<script type="text/javascript" defer="defer">
;(function(){
if ( !window.frames || !window.location.replace ) return;
var pages = [];
pages[0] = 'http://www.link1.com';
pages[1] = 'http://www.link2.com';
pages[2] = 'http://www.link3.com';
pages[3] = 'http://www.link4.com';
pages[4] = 'http://www.link5.com';
pages[5] = 'http://www.link6.com';
pages[6] = 'http://www.link7.com';
window.frames['hourFrame'].location.replace( pages[Math.floor(new Date().valueOf()/(1000*60*60))%pages.length] );
})();
</script>
</body>
</html>
Grim69
10-22-2014, 02:21 PM
Hi folks sorry for resurrecting such an old post.
I've trawled the internet for a long while before I found this solution.
I have used it and it is great but I do have a question.
Would it possible that the timed event was less random.
For instance I have used it for say 2 pages but I want 1 to be visible 80% of the time and the other 20%
Is this a realistic task?
Many thanks great site I think I will be spending more time here.
jscheuer1
10-22-2014, 04:42 PM
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<iframe name="hourFrame" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
<script type="text/javascript" defer="defer">
;(function(){
if ( !window.frames || !window.location.replace ) return;
var pages = [];
pages[0] = 'http://www.link1.com';
pages[1] = 'http://www.dynamicdrive.com';
var rand = Math.random() * 100;
rand = rand < 20? 0 : 1;
window.frames['hourFrame'].location.replace( pages[rand] );
var sf = arguments.callee;
setTimeout(function(){sf();}, 5000); // get rid of this line if you don't want it looping (5000) is the number of milliseconds per loop
})();
</script>
</body>
</html>
saskey
12-26-2014, 11:39 AM
Hi please can you help me with the code to generate a random url string with every visit. example http://www.mysite.com/a9nruiwe232rwerr whereby they all land on the same page but the url appears with different random extensions on the browser.
I would really appreciate your assistance.
keyboard
12-26-2014, 11:46 AM
If you have a question please start a new thread about it.
kelvinmurray
11-03-2016, 01:03 PM
Hi folks sorry for resurrecting such an old post.
I've trawled the internet for a long while before I found this solution.
I have used it and it is great but I do have a question.
Would it possible that the timed event was less random.
For instance I have used it for say 2 pages but I want 1 to be visible 80% of the time and the other 20%
Is this a realistic task?
Many thanks great site I think I will be spending more time here.
Hello,
Please can you help me with a script that will randomly change proxies and run it with this particular javascript. I mean a script that will change proxies as the website is randomly changing too. Thanks.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.