2013-04-01 53 views
0

是否可以使用新內容刷新頁面,哪些內容來自outerHTML?我有問題,我想刷新頁面,直到2秒,進行0-2秒以獲取帶有innerHTML的新HTML等。但是,我從outerHTML獲得新內容後。我很難用externalHTML中的HTML來刷新這個內容。Javascript替換內容並使用新內容刷新它來自externalHTML的新內容

下面我舉的例子代碼:

<script> 
    // code blablabla to get new content. This has been fix code, and below code to start refresh page with outerHTML. 
    window.onload = function() { 
     tes(); 
    }; 

    function tes() { 
     var htmlAll = document.documentElement.outerHTML; 
     setTimeout(function(){howCodeRefresh()}, 2000); 
     function howCodeRefresh() { 
      // how code to refresh page and replace all content with variable htmlAll 
     }; 
    }; 
</script> 

我的問題:是有可能做到這一點?如果是的話,該怎麼做?

謝謝。

回答

0

你是不是很清楚地解釋你的問題,你可以嘗試阿賈克斯jQuery的爲您解決question.Here是一個基本的演示:

<div id = "target"></div> 


    <script type="text/javascript" src="jquery.js"></script> 
    <script type="text/javascript"> 
     window.onload = loadHtml; 
     function loadHtml(){ 
      $.get("your/server/page.html",function(response){ 
        $("#target").html(response);  //Here is your html response 
      },'html'); 
     } 
    </script> 

Here is more document for jquery ajax.