Created
June 17, 2016 13:19
-
-
Save Rahe/3252a4569369a91ec070a4cfe27aa10f to your computer and use it in GitHub Desktop.
PostMessage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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