聽
domainA 涓湁涓€涓〉闈ndex.html锛岄€氳繃iframe宓屽浜哾omainB涓殑涓€涓〉闈ther.html
鐢变簬other.html椤甸潰鍦╥frame涓樉绀猴紝鑰屼笖鍏堕〉闈㈠唴瀹逛細鍔ㄦ€佺殑澧炲姞鎴栧噺灏戯紝鐜板湪闇€瑕佸幓鎺塱frame鐨勬粴鍔ㄦ潯
鐢变簬javascript鍚屾簮绛栫暐鐨勯檺鍒讹紝鏃犳硶杩涜璺ㄥ煙鎿嶄綔锛屼娇寰楅棶棰樻瘮杈冩鎵?/span>
鍙傝€冧簡涓€涓嬬綉涓婄殑鍋氭硶锛屽紩鍏ヤ簡涓€涓唬鐞嗛〉闈紝鎴栬€呭彨鍋氫腑浠?agent.html锛屽睘浜巇omainA
鐒跺悗锛屽湪domainB 涓殑other.html涓紝鍐嶄娇鐢╥frame灏哸gent.html杩涜宓屽
聽
濂戒簡锛岀幇鍦ㄦ儏鍐垫槸杩欐牱鐨勶細
index.html 浣跨敤iframe 宓屽 other.html
other.html 浣跨敤iframe 宓屽 agent.html
涔嬫墍浠ヨ寮曞叆绗?涓〉闈gent.html锛屽氨鏄负浜嗛伒瀹堚€滃悓婧愮瓥鐣モ€濈殑瑙勫垯锛屽畬鎴愪笉鍚宒omain涓嬪弬鏁扮殑浼犻€掞紒聽
聽
鎴戜滑鏈€缁堢殑鐩殑鏄鍘绘帀婊氬姩鏉★紝鍙堣淇濊瘉琚祵鍏ョ殑椤甸潰鍐呭鍏ㄩ儴寰楀埌鏄剧ず
1.鍙栧緱other.html椤甸潰鐨勫疄闄呴珮搴eight
2.灏唄eight璁剧疆鍒板叾宓屽叆鐨刬frame鐨剆rc灞炴€т笂
3.鍦╝gent.html涓埅鍙栧嚭鎵€灞瀒frame鐨剆rc灞炴€т腑鐨刪eight鍊?/span>
聽
涓嬮潰鐨勪緥瀛愪腑锛屼娇鐢ㄤ簡涓€涓妧宸э紝閬垮厤浜嗕娇鐢╯etInterval()涓嶆柇鍘昏缃甶frame鐨勯珮搴?/span>
鍋氭硶鏄湪iframe鐨剆rc涓婏紝闄勫姞涓€涓椂闂存埑锛岃娴忚鍣ㄦ瘡娆¢兘閲嶆柊鍔犺浇agent.html
杩涜€岃agent.hml涓殑js鍑芥暟invokeMethodInTopWindow()寰楀埌鎵ц
聽
domainA 涓殑2涓猦tml
index.html
#{extends 'main.html' /} #{set title:'Home' /} <hr> <div style="color:red;font-weight:bold">绐楀彛鑷€傚簲---缁曞紑鍚屾簮绛栫暐鐨勯檺鍒讹紝鍚屾椂鍙堝埄鐢ㄥ悓婧愮瓥鐣ワ紝鍘绘帀iframe鐨勬粴鍔ㄦ潯锛屽姩鎬佽皟鏁寸獥鍙g殑楂樺害锛岃鍏惰兘澶熸樉绀鸿宓屽椤甸潰鐨勬墍鏈夊唴瀹?lt;/div> <!-- 闇€瑕佸姩鎬佽皟鏁撮珮搴︾殑iframe --> <div style="text-align:center;"> <iframe name="domainB" src="http://127.0.0.1:8088/other" width="80%" scrolling="no" frameborder="0"></iframe> </div> <script type="text/javascript"> function resize(height) { //alert("resize"); document.getElementsByName("domainB")[0].height=height; } </script>
聽
agent.html
聽
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> 鎴戞槸浠g悊椤甸潰鍝︼紒 <script type="text/javascript"> window.onload = invokeMethodInTopWindow; function invokeMethodInTopWindow() { //alert("璋冪敤鍚屽煙涓嬬殑鍑芥暟锛岄噸缃甶frame鐨勯珮搴?); var domainA = document.parentWindow; var realHeight = domainA.location.hash.split("#")[1]; //last step:璋冪敤鏈€涓婂眰绐楀彛鐨勫嚱鏁帮紝閲嶇疆iframe鐨勯珮搴? parent.parent.resize(realHeight); //alert("realHeight:"+realHeight); //alert(document.parentWindow.name);//鑾峰彇瀹瑰櫒鎵€鍦ㄧ獥鍙g殑鍚嶇О domainA //error://alert(document.parentWindow.parent.name); //璁块棶澶辫触 锛氫笉鑳借闂甦omainB //alert(document.parentWindow.parent.parent.name);//鏈€椤跺眰window灞炰簬domainA锛屽洜姝ゅ彲浠ヨ闂? } //浣跨敤涓嶅悓鐨勬椂闂存埑璁剧疆iframe鐨剆rc灞炴€у悗锛屽氨涓嶇敤浣跨敤setInterval() //setInterval("invokeMethodInTopWindow()",100); </script> </body> </html>
聽
聽
domainB涓殑other.html
聽
<!DOCTYPE html> <html> <head> &l