A.S.F Studio A.S.F Studio - 2 months ago 5x
HTML Question

Setting the Iframe size after toggling

I have the following script running onload of the Iframe

<script type="text/javascript">

function getDocHeight(doc) {
doc = doc || document;
var body = doc.body, html = doc.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight );
return height;

function setIframeHeight(id) {
var ifrm = document.getElementById(id);
var doc = ifrm.contentDocument? ifrm.contentDocument: ifrm.contentWindow.document;
ifrm.style.visibility = 'hidden';
ifrm.style.height = "10px"; // reset to minimal height in case going from longer to shorter doc
ifrm.style.height = getDocHeight( doc ) + "px";
ifrm.style.visibility = 'visible';

However, in the Iframe there is an option to toggle (Jquery toggle()) which changes the size of the Iframe.

How can I launch the script above whenever the user clicks the toggle?


Call parent.setIframeHeight() in the toggle callback, with the correct iframe reference (perhaps using parent.getElementsByTagName('iframe')[0])