我在我的react应用程序中添加了一个外部CDN脚本,该应用程序有一个id="iframe-content"
并且该脚本在该ID中嵌入了一个iframe。现在,当此iframe的内容已完全加载时,我需要执行一些功能或更新状态。目前,我正在使用
window.addEventListener('load', (event) => {
callReady()
});
function callReady() {
// Get a handle to the iframe element
var iframe = document.getElementById('i_frame');
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// Check if loading is complete
if (iframeDoc.readyState == 'complete') {
iframe.contentWindow.onload = function () {
alert("I am loaded");
};
afterLoading();
return;
}
window.setTimeout(callReady, 100);
}
function afterLoading() {
alert("I am here");
}
我也尝试过
iframe.onload = function(event) {
console.log('loaded')
};
实际上没有任何效果,实际的iframe内容会在每个加载函数之后加载。我需要知道实际的iframe内容何时加载。你能在这里帮我吗?