A.S.F Studio
A.S.F Studio

Reputation: 43

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';
}
</script>

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?

Upvotes: 0

Views: 53

Answers (1)

jedifans
jedifans

Reputation: 2297

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

Upvotes: 1

Related Questions