View Single Post
 
Old December 2nd, 2010, 01:59 AM
Ryanvdm Ryanvdm is offline
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default auto resize iframe and Safari

Hi

I have the followinf code that works great in IE and FF but in safari only 50%

In Safari my iframe resizes when the content is larger that the carrent iframe size but doesnt "shrink" when the content in the iframe is shorter than the previous content.

Also I cannot use a script that uses the 'onload' event on the iframe as my client doesnt want the page to refresh.

any ideas would be helpfull.

Code:
<script type="text/javascript"><!--
function doIframe(){
    o = document.getElementsByTagName('iframe');
    for(i=0;i<o.length;i++){
        if (/\bautoHeight\b/.test(o[i].className)){
            setHeight(o[i]);
            addEvent(o[i],'load', doIframe);
        }
    }
}

function setHeight(e){
    if(e.contentDocument){
        e.height = e.contentDocument.body.offsetHeight + 35;
    } else {
        e.height = e.contentWindow.document.body.scrollHeight;
    }
}

function addEvent(obj, evType, fn){
    if(obj.addEventListener)
    {
    obj.addEventListener(evType, fn,false);
    return true;
    } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
    } else {
    return false;
    }
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);    
}
//--></script>



<iframe src="inc_rambleArticle.asp?ramblePostID=<%=ramblePostID%>" name="autosizeframe" id="autosizeframe" width="425" marginwidth="0" marginheight="0" align="left" scrolling="no" frameborder="0" class="autoHeight"></iframe>