Jump to content

Auto Refresh Twoif Rames On A Page


lional

Recommended Posts

Hi

I have two iframe ad banners on a page. I want each one to refresh every 8 seconds. One is on the far left and the other on the far right. I can only get one to refresh.

 

Here is my code

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/featuredcontentglider.js">/************************************************ Featured Content Glider script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts* This notice must stay intact for legal use***********************************************/</script>
<!--- Right hand iFrame --->
<script type="text/javascript"><!--
// set your interval in milliseconds
var reloadInterval = 8000;
// this will run when the document is fully loaded
function init() {
setTimeout('reload()',reloadInterval);
}
// this reloads the iframe, and triggers the next reload interval
function reload() {
var iframe = document.getElementById('reloader_lft', 'rht_reloader');
if (!iframe) return false;
iframe.src = iframe.src;
setTimeout('reload()',reloadInterval);
}
// load the init() function when the page is fully loaded
window.onload = init;
--></script>

<div id="banner_left">
<iframe src="banner_left.php" width="200" height="485" scrolling="no" id="reloader_lft" style="border:0px;padding:0px;margin-top:-6px"></iframe>
</div>
<div id="banner_right">
<iframe src="banner_left.php" width="200" height="485" scrolling="no" id="rht_reloader" style="border:0px;padding:0px;margin-top:-6px"></iframe>
</div>


 

Thanks

 

Lional

Link to comment
https://forums.phpfreaks.com/topic/270148-auto-refresh-twoif-rames-on-a-page/
Share on other sites

If you give them both the same class, you could do something like this. I'm assuming you want them to alternate reloading every 8 seconds, since you said load one. If you wanted to load both, just go through the class you set with a for loop and refresh them all.

 

var first = true;

setInterval(function()
{
   var n = first ? 0 : 1;
   window.document.getElementsByClassName("myClass")[n].contentwindow.location.reload();

   first = !first;
}, 8000);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.