Skip to content

Instantly share code, notes, and snippets.

@ianchadwick
Created February 14, 2016 10:52
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 ianchadwick/a4e277d641bf739063c9 to your computer and use it in GitHub Desktop.
Save ianchadwick/a4e277d641bf739063c9 to your computer and use it in GitHub Desktop.
Resize iframes cross domain for Mizmoz email previews
(function () {
var listenForWindowHeight = function (event) {
var parts = event.data.split('|');
// check the message is relevant
if (parts[0] != 'iframe-height') {
return;
}
// this check is only really needed if you have multiple iframes on the same page or are experiencing message name clashes
if (parts[1] != 'http://www.my-iframe-src.com/path') {
return;
}
// change the height of my iframe
document.getElementById('my-iframe-id').style.height = parts[2] + 'px';
};
// add the listener
window.addEventListener('message', listenForWindowHeight, false);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment