Skip to content

Instantly share code, notes, and snippets.

@Rahe
Created June 17, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rahe/3252a4569369a91ec070a4cfe27aa10f to your computer and use it in GitHub Desktop.
Save Rahe/3252a4569369a91ec070a4cfe27aa10f to your computer and use it in GitHub Desktop.
PostMessage
var origin = null;
if(window.addEventListener) {
window.addEventListener('message', onMessage, false);
} else {
window.attachEvent('onmessage', onMessage);
}
function onMessage(e) {
if(referer !== undefined && e.origin === referer) {
origin = e.origin;
var msg = JSON.parse(e.data);
switch(msg.cmd) {
case 'size':
_sendSize();
break;
default:
return e;
break;
}
} else {
return e;
}
}
function _getSize() {
setTimeout("_sendSize()", 200);
}
function _sendSize() {
var sendTo = origin !== null ? origin : '*';
var frameHeight = jQuery('body').children().first().height() + 25;
window.parent.postMessage(JSON.stringify({cmd:'size', value:frameHeight}), sendTo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment