2011-10-13 55 views
1

我在頁面上有多個iframe,需要從iframe的html元素訪問父iframe元素,以便獲取iframe的高度。從iframe中的元素遍歷到父iframe TAG

從這個

所以:

var htmlElement = $('iframe').contents().find('html'); 

下將無法正常工作:

var iframeHeight = htmlElement.parents('iframe').attr('height'); 

誰能幫助嗎?

+0

嘗試htmlElement.parent()。高度() – Evan

+0

「需要從iframe的html元素訪問父級Iframe元素,以獲得Iframes的高度。「 這就好像在說「我需要向前邁進並退後一步以便保持在同一位置」爲什麼不通過$('iframe')。attr('height');'或'each()'內置頁框並抓住它們的高度? –

回答

1

赦免,編輯(基於How to access parent Iframe from javascript

var iframe = null; 
parent.$("iframe").each(function(iel, el) { 
    if(el.contentWindow === window) 
     iframe = el; 
}); 
if (iframe) 
    iframe.height() 

這需要父窗口(有一個iframe的)有jQuery的