Travis2375
Travis2375

Reputation: 137

Refresh an iframe without refreshing the entire page

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>

Upvotes: 9

Views: 27980

Answers (4)

jiten jethva
jiten jethva

Reputation: 96

Use this:

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

It has to untie your issue.

Upvotes: 0

Mohit maru
Mohit maru

Reputation: 827

try this

window.top.location.reload();

Upvotes: -1

Anoop Joshi P
Anoop Joshi P

Reputation: 25527

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);
        });

Upvotes: 1

Milind Anantwar
Milind Anantwar

Reputation: 82231

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;

Upvotes: 5

Related Questions