Skip to content

Instantly share code, notes, and snippets.

@pilgreen
Created June 29, 2017 22:00
Show Gist options
  • Save pilgreen/4aca48966835ecb08dc364e3985f825f to your computer and use it in GitHub Desktop.
Save pilgreen/4aca48966835ecb08dc364e3985f825f to your computer and use it in GitHub Desktop.
Very basic seamless iframes
window.addEventListener("message", e => {
let d = e.data;
if(d.sentinel == 'gofer' && d.type == 'resize') {
let f = document.querySelector(`iframe[src="${d.location}"]`);
if(f && f.style) {
f.style.height = `${d.height}px`;
}
}
});
@pilgreen
Copy link
Author

Code on the iframe should be something like the following:

window.addEventListener('load', function(e) {
  window.parent.postMessage({
    sentinel: 'gofer',
    type: 'resize',
    height: document.body.scrollHeight,
    location: window.location.href
  }, '*');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment