比如 main.html 面的相關信息如下
<body >
<H1 id="h1Title"> H1內容</H1>
<iframe id="leftFrame" name="leftFrame" src="page/includes/left.html"></iframe>
<iframe id="centerFrame" name="centerFrame" width="537px" height="1000px" src="page/includes/center.html"></iframe>
</body>
如果 left.html 中想改變 main.html 中H1 的內容 則可以通過如下方式來改變
window.parent.document.getElementById("h1Title").innerHTML = "aabbccdd";
如果在center.html 要想執行left.html 中的JS函數 testLeft(),則方法如下:
top.window.frames["leftFrame"].testLeft() 即可。
注意事項: iframe 必須有 name 屬性 否則 在火狐瀏覽其中 top.window.frames["leftFrame"].*是不起作用的! 也就是找不大到對應“名稱”的iframe