JS/jQuery刷新iframe的方法


一、js 頁面刷新
1.  reload 方法,該方法強迫瀏覽器刷新當前整個頁面
  語法:location.reload([bForceGet])
  參數: bForceGet, 可選參數, 默認為 false,從客戶端緩存里取當前頁。true, 則以 GET 方式,從服務端取最新的頁面, 相當於客戶端點擊 F5("刷新")

<script language="JavaScript">
window.location.reload(true);
</script>

2.  刷新iframe 頁面

js方法1
document.getElementById('FrameID').contentWindow.location.reload(true);

js方法2
document.getElementById('youriframe').src=src;

例如:

<iframe id="firstFrame" width="100%" frameBorder="0" src="test.html" scrolling="no"></iframe>
<input type="button" onclick="javascript:refreshFrame();" value="Refresh Frame" />
 
<script type="text/javascript">
    function refreshFrame(){
        document.getElementById('firstFrame').contentWindow.location.reload(true);
    }
</script>

二.  jquery實現強制刷新

$('#iframe').attr('src', $('#iframe').attr('src'));

三.  如果是打開的新頁面,要刷新其他iframe,可以使用如下代碼

//刷新包含該框架的頁面用   
<script language=JavaScript>
   parent.location.reload();
</script>

//子窗口刷新父窗口
<script language=JavaScript>
    self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a> )

//刷新另一個框架的頁面用   
<script language=JavaScript>
   parent.另一FrameID.location.reload();
</script>

 


免責聲明!

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



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