How to Rotate randomly rotate iframe

amberlamps

BANNED
Joined
Jun 24, 2010
Messages
331
Reaction score
145
Okay i need to randomly rotate iframe/div on every page load or refresh


so say a visitor land on the page he his shown a random iframe


i will like to randomly show 10 iframes one per visitor randomly.

I looked every where and couldent find it, found text rotation, image and i tried to modify it to iframes but it just didnt work...


any help appreciated thank you

i need it to rotate a div, i figured out how to do it with a iframe but i need it cake sliced so i can iframe just a specific area

here the teext rotator i just sent time timeout to like 10000 it does waht i need it to do is rotate but it can only rotate iframe i need it to rotate div, hope i dont sound too confusing

Code:
<script language="JavaScript">
function rotateEvery(sec)
{
	var Quotation=new Array()

	// QUOTATIONS
	Quotation[0] = 'First quotation';
	Quotation[1] = 'Second quotation';
	Quotation[2] = 'Third quotation';
	Quotation[3] = 'Fourth quotation';
	Quotation[4] = 'Fiveth quotation';
	Quotation[5] = 'Sixth quotation';
	Quotation[6] = 'You can add <b>as many</b> quotations <b>as you like</b>';

	var which = Math.round(Math.random()*(Quotation.length - 1));
	document.getElementById('textrotator').innerHTML = Quotation[which];
	
	setTimeout('rotateEvery('+sec+')', sec*1000);
}
</script>
</head>
<body onload="rotateEvery(1)">
<div id="textrotator"><!--Quotations will be displayed here--></div>
 
Last edited:
This will show 1 random div.

Off the top of my head, so may not work. Shoot me a pm if it don't.
You'll need PHP. This must be a ,php page too.

Code:
<?php
$urls = array();
$divs[] = '<div>test</div>';
$divs[] = '<div>test2</div>';
$divs[] = '<div>test3</div>';



echo '<iframe src="'. $divs[rnd(0, count($divs)-1)] .'" />';

?>
Posted via Mobile Device
 
Last edited:
Never mind i figured it out.... lol i guess i just had to talk it out to myself lol
 
Instead of having it rotate text or images, you have it rotate a .php or .html page with your iframe code on it. Really easy to adapt any rotation script over to this.

Here's a basic RANDOM rotation script...

Code:
<?php

// random number 1 - 5
$result_random=rand(1, 5);

// if result equal 1, display ad 1
if($result_random=1){
echo ' ';
include("frame1.php");
}

// if result equal 2, display ad 2
elseif($result_random=2){
echo ' ';
include("frame2.php");
}

// if result equal 3, display ad 3
elseif($result_random=3){
echo ' ';
include("frame3.php");
}

// if result equal 4, display ad 4
if($result_random=4){
echo ' ';
include("frame4.php");
}

// if result equal 5, display ad 5
elseif($result_random=5){
echo ' ';
include("frame5.php");
}

?>

You should be able to adapt the variable to suit your needs.
 
thanks you guys for the quick reply.. appericated it this is how i did it with the text rotate code i had

orginal

Code:
<script language="JavaScript">
function rotateEvery(sec)
{
    var Quotation=new Array()

    // QUOTATIONS
    Quotation[0] = 'First quotation';
    Quotation[1] = 'Second quotation';
    Quotation[2] = 'Third quotation';
    Quotation[3] = 'Fourth quotation';
    Quotation[4] = 'Fiveth quotation';
    Quotation[5] = 'Sixth quotation';
    Quotation[6] = 'You can add <b>as many</b> quotations <b>as you like</b>';

    var which = Math.round(Math.random()*(Quotation.length - 1));
    document.getElementById('textrotator').innerHTML = Quotation[which];
    
    setTimeout('rotateEvery('+sec+')', sec*1000);
}
</script>
</head>
<body onload="rotateEvery(1)">
<div id="textrotator"><!--Quotations will be displayed here--></div>

ANd what i Did i cahneg the 'rotateEvery(1)" to like 5000 so it wont chaneg on me

and i added the dive where the quote went like this

'<div style="overflow: hidden; width: 413px; height: 282px; position: relative;" id="i_div">' + '<iframe name="i_frame" src="http://yahoo.com" style="border: 0pt none ; left: -393px; top: -131px; position: absolute; width: 1366px; height: 601px;" scrolling="no"></iframe></div>';

Example below

Code:
<script language="JavaScript">
function rotateEvery(sec)
{
var Quotation=new Array()

// QUOTATIONS
Quotation[0] = 'First quotation';
Quotation[1] = 'Second quotation';
Quotation[2] = 'Third quotation';
Quotation[3] = 'Fourth quotation';
Quotation[4] = 'Fiveth quotation';
Quotation[5] = 'Sixth quotation';
Quotation[6] = [COLOR=Red]'[B]<div style="overflow: hidden; width: 413px; height: 282px; position: relative;" id="i_div">' + '<iframe name="i_frame" src="http://yahoo.com" style="border: 0pt none ; left: -393px; top: -131px; position: absolute; width: 1366px; height: 601px;" scrolling="no"></iframe></div>[/B]';[/COLOR]

var which = Math.round(Math.random()*(Quotation.length - 1));
document.getElementById('textrotator').innerHTML = Quotation[which];

setTimeout('rotateEvery('+sec+')', sec*1000);
}
</script>
</head>
<body onload="rotateEvery([COLOR=Red][B]50000[/B][/COLOR])">
<div id="textrotator"><!--Quotations will be displayed here--></div>
The bold is what i changed i really dont know much i just copy and paste liek a mofo lol tahnks again everyone
 
Back
Top