// modified from same-domain version at www.dyn-web.com/tutorials/iframes/height/
function setIframeHeightCO(id, ht) {
console.log(ht);
var ifrm = document.querySelectorAll("iframe.field-iframe-instance")[0];
ifrm.style.visibility = 'hidden';
// some IE versions need a bit added or scrollbar appears
ifrm.style.height = ht + 4 + "px";
ifrm.style.visibility = 'visible';
}
// iframed document sends its height using postMessage
function handleDocHeightMsg(e) {
// check origin
if ( e.origin === 'http://web.barry-callebaut.com.com' ) {
// parse data
var data = JSON.parse( e.data );
// check data object
if ( data['docHeight'] ) {
console.log(data['docHeight']);
setIframeHeightCO( 'ifrm', data['docHeight'] );
} else if ( data['href'] ) {
setIframe('ifrm', data['href'] );
}
}
}
// assign message handler
if ( window.addEventListener ) {
window.addEventListener('message', handleDocHeightMsg, false);
} else if ( window.attachEvent ) { // ie8
window.attachEvent('onmessage', handleDocHeightMsg);
}