js頁面刷新之實現框架內外刷新(整體、局部)


這次總結的是框架刷新:

框架內外的按鈕均可以定義網頁重定向,

框架內部頁面的按鈕可以實現局部刷新,

框架外部頁面的按鈕可以實現整頁刷新。

代碼如下(兩個html頁面):

 1 <!--主界面index.html-->
 2     <iframe src="頁面刷新.html" frameborder="1"></iframe>
 3     <h1 id="iframeout">框架外內容</h1>
 4     <button onclick="fresh()">框架外刷新</button>
 5     
 6     <script>
 7         var h1 = document.getElementById('iframeout');
 8         function iframeout(){
 9             h1.style.color = "yellow";
10             h1.innerText = "我變化了";
11         }
12         setInterval(iframeout, 800);
13         function fresh(){
14             // 框架主頁面刷新,可以實現下面兩個功能:
15             top.location.reload();   //刷新整頁 
16             // window.parent.location.href='http://koushuling.top'; //框架頁重定向 
17         }
18     </script>
 1 <!--框架頁面:頁面刷新.html-->
 2    <style>
 3         body{
 4             background-color: gray;
 5         }
 6     </style>
 7    
 8     <h1 id="test">框架內頁面</h1>
 9     <button onclick="fresh()">框架內刷新</button>
10 
11     <script>
12         var h1 = document.getElementById('test');
13         function test(){
14             h1.style.color = "red";
15             h1.innerText = "我變化了";
16         }
17         setInterval(test, 1000);
18         function fresh(){
19             // 框架內頁面刷新:可實現局部刷新與整個頁面重定向
20              self.location.reload();  //刷新框架內頁面
21             // window.parent.location.href='http://koushuling.top'; //頁面重定向 
22         }
23 </script>
 

如有錯誤,請您更正!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM