18

I have this bit of code

<iframe marginwidth="0" marginheight="0" width="240" height="80" scrolling="no" frameborder=0 src="irc_online.php">
</iframe>

I am adding this to a html widget I have on a sidebar, Is there a way I can make this refresh say every 30 seconds and not the rest of my page?

peterh
  • 11,875
  • 18
  • 85
  • 108
VK27
  • 515
  • 2
  • 9
  • 19

5 Answers5

38

You can put a meta refresh Tag in the irc_online.php

<meta http-equiv="refresh" content="30">

OR you can use Javascript with setInterval to refresh the src of the Source...

<script>
window.setInterval("reloadIFrame();", 30000);

function reloadIFrame() {
 document.frames["frameNameHere"].location.reload();
}
</script>
ahmet2106
  • 4,957
  • 4
  • 27
  • 38
  • So did i do this wrong because it's not working (i can't seem to add a code box to this reply sorry) [code] [/code] – VK27 Feb 28 '11 at 20:07
  • Yes your (the name attribute) – ahmet2106 Feb 28 '11 at 20:10
  • It's not working for me. This is what i have - – VK27 Feb 28 '11 at 20:27
  • This worked out perfect in my current project. I have a meta refresh that does a download when completed, and I needed another redirect a few seconds later, to send the member back to the page they were on. I changed the document.frames, too // window.parent.location = "URL STRING HERE" Thank ahmet2106 – Wayne Barron Mar 05 '17 at 17:52
  • For some reason this only works for me (in chrome) if I use window.frames[...] as opposed to document.frames[...]. https://developer.mozilla.org/en-US/docs/Web/API/Window/frames – Xanderak Feb 25 '22 at 03:17
16

Let's assume that your iframe id= myIframe

here is the code:

<script>
window.setInterval("reloadIFrame();", 30000);
function reloadIFrame() {
 document.getElementById("myIframe").src="YOUR_PAGE_URL_HERE";
}
</script>
SymbianSyMoh
  • 161
  • 1
  • 4
6

Okay... so i know that i'm answering to a decade question, but wanted to add something! I wanted to add a google calendar with special iframe parameters. Problem is that the calendar didn't work without it. 30 seconds is a bit short for my use, so i changed that in my own file to 15 minutes This worked for me.

<script>
window.setInterval("reloadIFrame();", 30000);
function reloadIFrame() {
 document.getElementById("calendar").src=calendar.src;
}
</script>

    <iframe id="calendar" src="[URL]" style="border-width:0" width=100% height=100% frameborder="0" scrolling="no"></iframe>
T. Willemse
  • 71
  • 1
  • 3
1

I have a simpler solution. In your destination page (irc_online.php) add an auto-refresh tag in the header.

DDev
  • 17
  • 7
Sush
  • 1,169
  • 1
  • 10
  • 26
0

add "id='myiframe'" to the iframe, then use this script :

<script>

function f1()
{
 var x=document.getElementById("myiframe");
   x.src=x.src+Math.floor(random()%100000);
}

setInterval(f1,30*1000);

</script>
AbiusX
  • 2,379
  • 20
  • 26
  • Where would i put this function f1() { var x=document.getElementById("myiframe"); x.src=x.src+Math.floor(random()%100000); } setInterval(f1,30*1000); it just show's on my page Thanks – VK27 Feb 28 '11 at 20:09