A.S.F Studio A.S.F Studio - 1 year ago 78
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download