2013-04-04 39 views
-1

所以我有這樣的腳本:我如何每20秒重新加載一個div?

<script id="_wauwgs">var _wau = _wau || []; _wau.push(["small", "p00ystfryeuc", "wgs"]); 
    (function() {var s=document.createElement("script"); s.async=true; 
    s.src="http://widgets.amung.us/small.js"; 
    document.getElementsByTagName("head")[0].appendChild(s); 
})();</script> 

,我想重新加載它每隔20秒或30秒。我試着用這個:

<script type="text/javascript"> 
    function refresh() { 
    document.getElementById('online').src = document.getElementById('online').src; 
    } 
    window.setInterval("refresh()",30000); 
</script> 

用腳本<div id="online"></div>但它沒有工作。

+0

也許最好從腳本中調用函數,而不是完全重新加載腳本?請注意,該緩存也可能會阻止完全重新加載。 – VisioN 2013-04-04 08:37:54

回答

1

我想這是你想要什麼:

setInterval(function(){ 
    $("#online").attr('src', 'http://widgets.amung.us/small.js', 3000 /*or 2000*/); 
}) 
0

我想刷新腳本的唯一方法是重新插入。

var script = $('#online').html(); 
     function reloadScript() { 
      $time = 500; 
      $('#online').html(''); 
      setTimeout(function() { 
       $('#online').html(script); 
       reloadScript(); 
      }, $time); 
     } 
     reloadScript(); 
+0

您將再次添加相同的內容。這裏重裝的用途是什麼? – 2013-04-04 08:49:07

相關問題