iframe控制主視窗和子視窗的重新整理

來源:互聯網
上載者:User
iframe控制主視窗和子視窗的重新整理

大家好,這裡我將向大家講解怎麼在iframe視窗裡面控制他的父視窗,最上層視窗和本身視窗的頁面重新整理。
下面是兩種html的代碼
首先是主視窗.html========================================================= <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>iframe控制主視窗和子視窗重新整理--主視窗</title> <script type="text/javascript">     function onloadFun(){         alert("重新整理主視窗");     } </script> </head> <body onload="onloadFun()">     <div style="border:#FF0000 1px solid">        主視窗        <iframe width="300px" height="300px" src="iframe子視窗.html" marginheight="0px" marginwidth="0px" frameborder="0" scrolling="no"></iframe>     </div> </body> </html>


接下來是iframe子視窗.html==================================================== <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>iframe控制主視窗和子視窗重新整理--子視窗</title>

    <script type="text/javascript">     function 重新整理頂級主表單Fun(){        top.location.href=top.location.href;//重新整理頂級頁面     }     function 重新整理iframe子表單Fun(){        location.href=location.href;     }     function 重新整理父級表單Fun(){        parent.location.href=parent.location.href;        alert("重新整理父視窗");     }     function onloadFun(){        alert("重新整理子視窗");     } </script>

    </head>

    <body onload="onloadFun()">     <div style="border:#FF00ff 1px solid">         子視窗<br/>         <button onclick="重新整理頂級主表單Fun()">重新整理頂級主表單</button><br/>         <button onclick="重新整理iframe子表單Fun()">重新整理iframe子表單</button><br/>         <button onclick="重新整理父級表單Fun()">重新整理父級表單</button><br/>     </div> </body> </html>
下面是運行效果: 首先是點擊(重新整理頂級主表單)按鈕效果: ——》

點擊(重新整理iframe子表單)按鈕效果:
點擊(重新整理父級表單)按鈕效果:
——》 ——》

這裡要特別注意:location.href和parent.location.href在ie模式下可以在本地運行,在360瀏覽器下有可能會被阻止運行。不過在項目部署裡面發布後不會被阻止。


文章來源: http://www.xingchen900.com/webProj/BaoXiaoWeb/WebMould/mould.html?htmlID=f763e62da83344495980cda8b6c1baf4b.html



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.