[英]iframe onload fires when iframe is not ready
所以我在香草反應中有問題。 我在ready()
函數中有以下代碼行:
var current = this;
React.createElement(
"iframe",
{id: "iframeController",
ref: "iframe",
src: "data:text/html;charset=utf-8," + escape(notification.description),
onLoad: current.iframeLoaded(this)}
)
notification.description來自我對this.state.notifications
中的對象所做的this.state.notifications
並遵循此功能
iframeLoaded(iframe) {
if(iframe) {
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
}
}
但是,如果我在iframeLoaded中console.log(iframe)元素,則返回null。 如果我getElementById也是一樣,除了它是未定義的。
我做了一個setTimeout,看看它是否是一個組件更新問題,事實證明是這樣。 因此,即使在Chrome中,onLoad也會在src有時間呈現之前觸發。
我正在嘗試獲取高度,以便可以將其設置在窗口中,以允許其調整大小並獲取要獲取的iframe的全部高度。
誰能給我有關如何解決此問題的提示?
我懷疑問題在於此行: onLoad: current.iframeLoaded(this)}
。 在這種情況下, onLoad
設置為current.iframeLoaded(this)
的返回值。
我相信您希望將值包裝在函數中(不是箭頭符號,而是傳統函數):
onLoad: function(){current.iframeLoaded(this);}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.