Created
February 14, 2016 10:52
-
-
Save ianchadwick/a4e277d641bf739063c9 to your computer and use it in GitHub Desktop.
Resize iframes cross domain for Mizmoz email previews
This file contains hidden or 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
(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