- Add the iframe in your page.
<iframe id="BTMCFrame" src="https://truemusiccyprus.com/" onload="resizeBTMCFrame(this)"></iframe>
- Create the
resizeBTMCFrame
function that posts a message to the iframe to request its height.
function resizeBTMCFrame(frame) {
frame.contentWindow.postMessage('FrameHeight', '*')
}
- Add an event listerner to handle the received height from the iframe and adjust the frame's height.
window.addEventListener('message', function (event) {
if (event.data.hasOwnProperty('FrameHeight')) {
document.getElementById('BTMCFrame').style.height = event.data.FrameHeight + 'px'
}
})
For a reference implementation see this page.