Created
March 19, 2014 15:42
-
-
Save jbritten/9644478 to your computer and use it in GitHub Desktop.
Dynamically resize Prefinery's iframe form height.
This file contains 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
/* | |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can we remove the height attribute from the iframe declaration?