9

I have an iframe that I would like to automatically refresh itself without doing a whole page refresh. I would prefer to use javascript or jquery. This is what I have been trying unsuccessfully.

<div class="Widget"><!--DARK SKY-->
 <div class="WidgetHeader">
 <img src = "images/WidgetHeaders/DarkSky.png"></div>
 <div id="DarkSky" style="width: auto; height: 245px; padding: 5px; background-color: hsla(0,0%,100%,.9);">
 <iframe id="forecast_embed" type="text/html" frameborder="0" height="245" width="100%" src="http://forecast.io/embed/#lat=38.269571&lon=-85.487420&name=Louisville&units=us&color=#4c7cba"> </iframe>
 </div> 
</div>
<script type = "text/javascript">
 window.onload = function() { 
 setInterval(function refreshDarkSky() { 
 document.getElementById("#forecast_embed").src ="http://forecast.io/embed/#lat=38.269571&lon=-85.487420&name=Louisville&units=us&color=#4c7cba"
 }, 90000);
 } 
</script>
RevanthKrishnaKumar V.
1,9031 gold badge22 silver badges35 bronze badges
asked Feb 21, 2014 at 14:29

4 Answers 4

5

if iframe is not from different domain, you can use:

document.getElementById('forecast_embed').contentDocument.location.reload(true);

for cross domain,

var iframe = document.getElementById('forecast_embed');
iframe.src = iframe.src;
answered Feb 21, 2014 at 14:31
Sign up to request clarification or add additional context in comments.

Comments

1

try this code

$(document).ready(function () {
 setInterval(function refreshDarkSky() {
 $("#forecast_embed").attr("src","http://forecast.io/embed/#lat=38.269571&lon=-85.487420&name=Louisville&units=us&color=#4c7cba"); 
 }, 90000);
 });
answered Feb 21, 2014 at 14:31

4 Comments

Can you provide your html?
just added it, sorry for not getting that on there from the start
It will take almost 9 minutes to reload thw content. Change 90000 with 9000 for testing purpose
yes, but it displays weather information. Weather info doesn't change that quickly. I always give it plenty of time to refresh when testing.
0

Use this:

$('#forecast_embed',window.parent.document).attr('src',
 $('#forecast_embed',window.parent.document).attr('src'));

It has to untie your issue.

Alexey Subach
12.4k7 gold badges40 silver badges62 bronze badges
answered Nov 6, 2017 at 10:58

Comments

-1

try this

window.top.location.reload();
rink.attendant.6
46.7k64 gold badges111 silver badges161 bronze badges
answered Mar 27, 2015 at 6:53

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.