1. 程式人生 > >子頁面呼叫父頁面的js方法

子頁面呼叫父頁面的js方法

1)iframe呼叫父頁面的js

window.parent.freshList();

2)iframe呼叫多層的父頁面的js

以自定義查詢新增查詢條件的頁面newCustom.jsp為例:

var frames=window.parent.parent.window.document.getElementById("operateIframe").

      contentWindow.document.getElementById("descriptIframe");
frames.contentWindow.customSearch(queryId);

window.parent 為包含該Ifame(newCustom.jsp)的頁面mainCustom.jsp

window.parent.parent 為彈出查詢條件設定頁面(mainCustom.jsp)的父頁面mainPage.jsp.

window.parent.parent.window.document.getElementById("operateIframe")為獲得mainPage.jsp的iframe的著錄功能的主頁面frame.jsp

window.parent.parent.window.document.getElementById("operateIframe").contentWindow.document.getElementById("descriptIframe")為frame.jsp頁面左側選單樹旁邊的右側顯示查詢結果的表格頁面archivesPage.jsp。

customSearch(queryId)為這個頁面擁有的js,archivesPage.js中的方法。