<iframe
src="https://example.com/widget"
width="600" height="400"
loading="lazy"
title="Калькулятор стоимости" <!-- важно для доступности -->
referrerpolicy="strict-origin-when-cross-origin"
allow="fullscreen; geolocation; clipboard-read"
sandbox="allow-scripts allow-same-origin">
</iframe>
<iframe srcdoc="<h1>Привет</h1><p>Встроенный контент</p>" title="Демо"></iframe>
// Родитель
iframeEl.contentWindow.postMessage({type:'SET_COLOR', value:'#0ea5e9'}, 'https://widget.example');
// В фрейме
window.addEventListener('message', (e) => {
if (e.origin !== 'https://parent.example') return;
// обработать e.data
});
<div class="video">
<button class="video__play">▶ Смотреть</button>
</div>
<script>
document.querySelector('.video__play').addEventListener('click', (e) => {
e.currentTarget.parentNode.innerHTML =
'<iframe src="https://www.youtube-nocookie.com/embed/ID?autoplay=1" ' +
'title="Видео" allow="accelerometer; autoplay; encrypted-media" allowfullscreen></iframe>';
});
</script>
.embed {
aspect-ratio: 16 / 9;
width: 100%;
}
.embed iframe {
width: 100%;
height: 100%;
border: 0;
}
<div class="embed">
<iframe src="..." title="Видео" loading="lazy" allowfullscreen></iframe>
</div>