Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maneja81/1729f485b027c8f8574a to your computer and use it in GitHub Desktop.
Save maneja81/1729f485b027c8f8574a to your computer and use it in GitHub Desktop.
Passing variables between iframe and parent window
// Iframe
function resize() {
var height = $(html).height();
// Backwards – send message to parent
window.parent.postMessage(['varName', var_value], '*');
}
// Parent
window.addEventListener('message', function (e) {
var $iframe = $('#the-iframe');
var eventName = e.data[0];
var data = e.data[1];
switch (eventName) {
case 'varName':
alert(data);
break;
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment