繁体   English   中英

刷新iframe而不刷新整个页面

[英]Refresh an iframe without refreshing the entire page

我有一个iframe,我想自动刷新自己而不进行整页刷新。 我更喜欢使用javascript或jquery。 这是我一直尝试失败的原因。

<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>

如果iframe不是来自不同的域,您可以使用:

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

对于跨域,

var iframe = document.getElementById('forecast_embed');
iframe.src = iframe.src;

试试这段代码

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

用这个:

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

它必须解开你的问题。

尝试这个

window.top.location.reload();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM