我在使用javascript在加載時注入iframe的大小時遇到問題。我使用大約300px的設置寬度,這很好,但動態地將iframe的高度調整爲其內容大小(博客文章)。在加載後調整iframe的大小
我試着讓contentWindow(沒有孩子dom元素)和contentDocument(這是未定義的)無濟於事。
我這樣做負載:
var iframe = document.createElement('iframe');
iframe.setAttribute('id','postFrame');
iframe.setAttribute('frameborder','no');
iframe.setAttribute('scrolling','no');
iframe.setAttribute('onload','resizeFrame();');
iframe.setAttribute('width','300px');
iframe.setAttribute('src','http://espn.go.com/espn/print?id=7454651');
var container = document.getElementById('container');
container.appendChild(iframe);
function resizeFrame(){ /* resize iframe based on content height*/ }
有沒有辦法基礎上的iframe中的內容重新大小iframe的高度?
*編輯**
可能的解決方法:
是否有希望,我可以使用訪問控制允許來源,以幫助這個問題?可以說iframe中的頁面是我自己的,或者是來自php腳本的echo'd
我假設你不擁有'espn.go.com',在這種情況下,我在這幾個月的工作中做了很多工作 - 它依賴於'客戶'和' 'supplier'(你會是其中之一,espn.go.com會是其中一個)。如果你私下聯繫我,我認爲最好,所以我可以通過Skype與你談談。如果您將Skype用戶名留在此處,我會添加您並嘗試提供幫助。 – ClarkeyBoy 2012-01-12 23:23:31
嗯我不使用skype – mbuff24 2012-01-13 01:19:29