js實現重新整理iframe的方法匯總

來源:互聯網
上載者:User

js實現重新整理iframe的方法匯總

 js實現重新整理iframe的方法匯總

這裡給大家匯總了一些js實現重新整理iframe架構的方法,非常的簡單實用,有需要的小夥伴可以參考下。

 

 

javascript實現重新整理iframe的方法的總結,現在假設存在下面這樣一個iframe,則重新整理該iframe的N種方法有:

 

 代碼如下:


<iframe src="1.htm" name="ifrmname" id="ifrmid"></iframe>

 

第一種方法:用iframe的name屬性定位

 

代碼如下:


<input type="button" name="Button" value="Button" onclick="document.frames('ifrmname').location.reload()">

 

或者

 

複製代碼 代碼如下:


<input type="button" name="Button" value="Button" onclick="document.all.ifrmname.document.location.reload()">

 

第二種方法:用iframe的id屬性定位

 

複製代碼 代碼如下:


<input type="button" name="Button" value="Button" onclick="ifrmid.window.location.reload()">

 

第三種方法:當iframe的src為其它網站地址(即跨網域作業時)

 

複製代碼 代碼如下:


<input type="button" name="Button" value="Button" onclick="window.open(document.all.ifrmname.src,'ifrmname','')">

 

父頁面中存在兩個iframe,一個iframe中是一個連結清單,其中的連結指向另一個iframe,用於顯示內容。現在當內容內容添加後,在連結清單中添加了一條記錄,則需要重新整理列表iframe。
在內容iframe的提交js中使用parent.location.reload()將父頁面全部重新整理,因為另一個iframe沒有預設的url,只能通過列表選擇,所以只顯示了列表iframe的內容。
使用window.parent.frames["列表iframe名字"].location="列表url"即可進重新整理列表iframe,而內容iframe在提交後自己的重新整理將不受影響。

 

 代碼如下:


document.frames("refreshAlarm").location.reload(true);
document.frames("refreshAlarm").document.location.reload(true);
document.frames("refreshAlarm").document.location="http://www.jb51.net/";
document.frames("refreshAlarm").src="http://www.jb51.net/";

 

注意區別:document.all.refreshAlarm 或 document.frames("refreshAlarm") 得到的是http://www.jb51.net/頁面中那個iframe標籤,所以對src屬性操作有用。
document.frames("refreshAlarm").document得到iframe裡面的內容,也就是"http://www.jb51.net/"中的內容。

javascript(js)自動重新整理頁面的實現方法總結:

間隔10秒重新整理一次,在頁面的head標籤中加入下面的程式碼片段:

 

代碼如下:


<meta http-equiv="refresh"content="10;url=跳轉的頁面或者是需要重新整理的頁面URL地址">

 

定時重新整理頁面(間隔2秒重新整理一下頁面):

 

代碼如下:


<script language="javascript">
setTimeout("location.href='url'",2000);//url是要重新整理的頁面URL地址
</script>

 

直接重新整理頁面事件:

 

代碼如下:


<script language="javascript">
window.location.reload(true);
//如需重新整理iframe,則只需把window替換為響應的iframe的name屬性值或ID屬性值
</script>

 

直接重新整理頁面事件:

 

代碼如下:


<script language=''javascript''>
window.navigate("本頁面url");
</script>

 

直接重新整理頁面事件:

 

 代碼如下:


function abc(){
window.location.href="/blog/window.location.href";
setTimeout("abc()",10000);
}

 

重新整理架構頁:

 

代碼如下:


<script language="javascript">
top.leftFrm.location.reload();
parent.frmTop.location.reload();
</script>

 

以上所述就是本文的全部內容了,希望大家能夠喜歡。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.