這次總結的是框架刷新:
框架內外的按鈕均可以定義網頁重定向,
框架內部頁面的按鈕可以實現局部刷新,
框架外部頁面的按鈕可以實現整頁刷新。
代碼如下(兩個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>
如有錯誤,請您更正!