I have a cross-domain iframe inside one of my page, its content should use the window.parent.postMessage
method to notify it is rendered to the containing page (so it can adjust iframe's height to its content). It works quite well, but only once, if I start clicking in the iframe and browsing different pages, the load event does not get triggered anymore even if all the pages in the iframe contains the same JavaScript code (see below).
here's the container's code let's say container.js:
function onMessage(jqEvent) {
if (jqEvent.originalEvent.data.iframe) {
var iframeContentHeight = jqEvent.originalEvent.data.iframe;
$('iframe').height(iframeContentHeight + 300);
}
}
$(window).on('message.socialPanel', onMessage);
and here is the code inside the iframe (it is in an external file, let's call it iframe.js):
$(window).on('load', function () {
var height = $('html').height();
window.parent.postMessage({'iframe': height}, '*');
});