function updateSize() { var body = document.body, html = document.documentElement; var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); height = Math.max(body.scrollHeight, body.offsetHeight); height = jQuery('body').innerHeight(); var obj = {eventType: 'updateContentSize', params: {height: height}}; window.parent.postMessage(obj, '*') } /* Use for FAQ */ function onElementHeightChange(elm, callback) { var lastHeight = elm.clientHeight, newHeight; (function run() { newHeight = elm.clientHeight; if (lastHeight != newHeight) callback(); lastHeight = newHeight; if (elm.onElementHeightChangeTimer) clearTimeout(elm.onElementHeightChangeTimer); elm.onElementHeightChangeTimer = setTimeout(run, 20); })(); } window.addEventListener('message', function(e) { var message = e.data; if (message) { if (message.eventType) { switch (message.eventType) { case 'getAnchorPosition' : { if (message.params && message.params.anchor) { var currentAnchor = jQuery(message.params.anchor); if (currentAnchor.length) { console.log(currentAnchor.position().top); var obj = { eventType: 'responseAnchorPosition', params: {top: currentAnchor.position().top} }; window.parent.postMessage(obj, '*') } } break; } default: { break; } } } } }); jQuery(window).load(function() { jQuery('a:not([target]), a[target="_self"]').attr('target', '_parent'); updateSize(); /* Use for FAQ */ onElementHeightChange(document.body, function() { updateSize(); }); }); jQuery(window).resize(function() { updateSize(); });