...

View Full Version : IFrame auto resize in safari



mbarandao
12-08-2010, 05:51 PM
Hello:

I'm using this script as an auto resize function for an iframe, but can't get it to work in safari.



<script type="text/javascript">
<!--
function calcheight()
{
var the_iframe = document.getElementById('paymentHistory');
var the_document = (the_iframe.contentWindow the_iframe.contentDocument);
if(the_document.document) the_document = the_document.document;
var the_height= the_document.body.scrollHeight;}
//-->
</script>


to call the function, I have

<iframe id="paymentHistory" onload="calcHeight()" src="/andy/admin/categories/printpaymenthistory.php"></iframe>


any thoughts as to what is wrong?

Logic Ali
12-08-2010, 06:23 PM
any thoughts as to what is wrong?
That function returns nothing and assigns nothing to any element's property, therefore it does nothing in any browser.

mbarandao
12-08-2010, 06:52 PM
I thank you sir! Let me restate my intention:

I previously was using this function for Iframe resizing:



<script type="text/javascript"><!--
function calcHeight(elem)
{
var the_height=50;
var padding=30;
try
{
if( elem.contentWindow && elem.contentWindow.document)
{
the_height=elem.contentWindow.document.body.scrollHeight;
}
}
catch(e){}
elem.height=the_height +padding;
}
//--></script>


this function works fine in ie and ff but not safari. I'm currently working on a project that I need to run only on safari. I need to find a fix to enable the calcHeght() to work.

My earlier post was a suggestion --which I have not been able to communicate with the original author.

So, can someone assist with causing the above function to work in safari or make another recommendation.

Thank you!
Mossa

Logic Ali
12-08-2010, 09:35 PM
It just needed a slight change in the addressing.
Note that under the current Chrome, this will fail under the file:/// protocol due to what it perceives as an unsafe access attempt.


<script type='text/javascript'>

function calcHeight(elem)
{
var the_height=50;

var padding=30;

if( elem.contentWindow )
try
{
the_height = elem.contentWindow.document.documentElement.scrollHeight;
}
catch(e){}

elem.height = the_height + padding;
}

</script>

<iframe src='mypage.htm' onload='calcHeight(this)' ></iframe>

mbarandao
12-08-2010, 10:22 PM
Thank you very much for the re-write. On first attempt, it still doesn't seem to work in safari. I have to run to a meeting now; I will attempt again when I return.

I'll advise..

Again, thank you
Mossa



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum