IFrame communication

From parent to child and from child to parent.

Jul 22, 2021 | - views

Container is not ready

// child
document.addEventListener('DOMContentLoaded', () => {
    window.parent.notifyAboutReady();
});
window.updateValue = (value) => {
    document.getElementById('counter').innerText = value;
}

// parent
window.notifyAboutReady = () => {
    document.getElementById('is-ready-container').innerText = 'Container is ready'
}
document.addEventListener('DOMContentLoaded', () => {
    const frame = window.frames['container'];

    let i = 0;
    setInterval(() => frame.updateValue(i++), 1_000);
});