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
Travis2375
1371 gold badge1 silver badge5 bronze badges
4 Answers 4
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
Milind Anantwar
82.3k26 gold badges97 silver badges128 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Anoop Joshi P
25.6k9 gold badges35 silver badges54 bronze badges
4 Comments
Anoop Joshi P
Can you provide your html?
Travis2375
just added it, sorry for not getting that on there from the start
Anoop Joshi P
It will take almost 9 minutes to reload thw content. Change 90000 with 9000 for testing purpose
Travis2375
yes, but it displays weather information. Weather info doesn't change that quickly. I always give it plenty of time to refresh when testing.
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
jiten jethva
1061 silver badge5 bronze badges
Comments
try this
window.top.location.reload();
rink.attendant.6
46.7k64 gold badges111 silver badges161 bronze badges
answered Mar 27, 2015 at 6:53
Mohit maru
8238 silver badges15 bronze badges
Comments
Explore related questions
See similar questions with these tags.
lang-js