Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    338
    Thanks
    22
    Thanked 1 Time in 1 Post

    IFrame auto resize in safari

    Hello:

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

    Code:
    <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
    Code:
    <iframe id="paymentHistory" onload="calcHeight()" src="/andy/admin/categories/printpaymenthistory.php"></iframe>
    any thoughts as to what is wrong?

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    338
    Thanks
    22
    Thanked 1 Time in 1 Post
    I thank you sir! Let me restate my intention:

    I previously was using this function for Iframe resizing:

    Code:
    <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

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    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.

    Code:
    <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>

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    338
    Thanks
    22
    Thanked 1 Time in 1 Post
    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
    Last edited by mbarandao; 12-08-2010 at 09:33 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •