Skip to content

Instantly share code, notes, and snippets.

@jbritten
Created March 19, 2014 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbritten/9644478 to your computer and use it in GitHub Desktop.
Save jbritten/9644478 to your computer and use it in GitHub Desktop.
Dynamically resize Prefinery's iframe form height.
/*
It can be difficult to size an iframe properly. The inherit problem
with iframes is that your page controls the size, yet the iframe itself
takes up space. Fortunately, communication is possible across domains
using something called postMessage. This javascript is simply a
cross-browser implementation on how to receive Prefinery's message
containing the form's height so that your iframe's height is set automatically.
You should remove the "height" attribute from your iframe declaration and
post this code in your page's <head>
*/
<script type="text/javascript">
var PrefineryEventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var PrefineryReceiveMessage = window[PrefineryEventMethod];
var PrefineryMessageEvent = PrefineryEventMethod == "attachEvent" ? "onmessage" : "message";
PrefineryReceiveMessage(PrefineryMessageEvent, function(e) {
var message = e.data.split('|');
if (message[0] == "PrefineryIFrameHeight") {
document.getElementById('prefinery_iframe_inline').style.height = message[1] + "px";
}
}, false);
</script>
@Tenkir
Copy link

Tenkir commented Mar 7, 2016

How can we remove the height attribute from the iframe declaration?

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