1. 程式人生 > >iframe父頁面與子頁面的互動

iframe父頁面與子頁面的互動

<iframe id="child" name="child" src="child.html"></iframe>

1.父頁面獲取子頁面的window物件

var childiframeWin = document.getElementById("child").contentWindow;//通過iframe標籤的id獲取

獲取到子頁面的window後,就可以通過window獲取到子頁面的物件和方法。

2.子頁面獲取父頁面的window物件

var parentiframeWin = window.parent;

獲取到父頁面的window後,就可以通過window獲取到父頁面的物件和方法。