Solved

cross browser iframe auto resixe script/solution

Posted on 2008-10-18
21
939 Views
Last Modified: 2010-07-08
*Please don't submit a googled cut and snip solution. Please only submit one that you have tested and it works*

Need a tried and true cross browser Iframe auto resize script. Googled solutions so far have not worked.

My IFrame:

<iframe name="bodyframe" src="../site_flash/privacypolicyu.htm" height="680" width="758" SCROLLING=NO frameborder="0"  >
0
Comment
Question by:Wanderinglazyeye
  • 11
  • 10
21 Comments
 
LVL 16

Expert Comment

by:sh0e
Comment Utility
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23826632.html
I just rewrote part of a script for someone else here trying to do the same thing.

Anyhow, this is how I would code it.  Tested on WebKit, IE6, FireFox 3.
<iframe name="bodyframe" src="../site_flash/privacypolicyu.htm" height="680" width="758" SCROLLING=NO frameborder="0"  onload="resizeIframe(this)"> 

<script type="text/javascript">

function resizeIframe(name) {

      i=name;

      ih = i.document ? i.Document.body.scrollHeight : i.contentDocument.body.scrollHeight;

      i.style.height = ih + 5 + "px";

}

</script>

Open in new window

0
 
LVL 16

Expert Comment

by:sh0e
Comment Utility
Sorry, I pasted the wrong code.  My editor has been glitching on me a lot lately.
<script type="text/javascript">

function resizeIframe(name) {

      i=name;

      ih = i.document ? i.Document.body.scrollHeight : i.contentDocument.body.scrollHeight;

      i.style.height = ih + 5 + "px";

}

</script>
 
 

<iframe name="bodyframe" src="../site_flash/privacypolicyu.htm" height="680" width="758" SCROLLING=NO frameborder="0"  onload="resizeIframe(this)"> 

Open in new window

0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
The firefox browser isn't displaying the iframe.

I put the script in the head section and the iframe line in the body. I am getting an ivalid markup for that line in Dreamweaver??

Says marked invalid becuase its overlapping or unclosed...
<iframe name="bodyframe" src="../site_flash/index_i.htm" height="680" width="758" SCROLLING=NO frameborder="0"  onload="resizeIframe(this)">  

Open in new window

0
 
LVL 16

Expert Comment

by:sh0e
Comment Utility

<script type="text/javascript">

function resizeIframe(name) {

      i=name;

      ih = i.document ? i.Document.body.scrollHeight : i.contentDocument.body.scrollHeight;

      i.style.height = ih + 5 + "px";

}

</script>

 

 

<iframe name="bodyframe" src="../site_flash/privacypolicyu.htm" height="680" width="758" SCROLLING=NO frameborder="0"  onload="resizeIframe(this)"></iframe>

Open in new window

0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
Hi Shoe,

Its still cutting off part of the webpage in the IFrame. Its not sizing it for the whole page...

By specifying the height and width in the Iframe is this messing up the script?
0
 
LVL 16

Expert Comment

by:sh0e
Comment Utility
No, it should have no effect on the script.
I have tested the script without problem.  Is it possible for you to show me a demo site for which you are having trouble?
0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
I am in the process of setting up the testing account. It will be within 24 hours. In the mean time is there any other way you can evaluate this? The source code is being written in DW. I can post or send the file, or we can wait until the test site is up - either.
0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
Here it is:

www.xf-fps.com/index.html

Please ignore the 404 error below.
0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
See,its cutoff at the bottom...
0
 
LVL 16

Expert Comment

by:sh0e
Comment Utility
<iframe name="bodyframe" src="../privacypolicyu.htm" height="680" width="758" scrolling="no" frameborder="0" onload="resizeIframe(this)" ></iframe>

The page has a typo, missing the closing quote.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Wanderinglazyeye
Comment Utility
Still not functioning correctly. Check the code at the site again...should I substitute name in the script with the I frame name?

www.xf-fps.com/index.html (updated)
0
 
LVL 16

Expert Comment

by:sh0e
Comment Utility
Apparently, the FF part I wrote wasn't working right.
May break when browser developers feel like messing with DOM names again.

<script type="text/javascript">

function resizeIframe(name) {

      i=name;

      ih = i.document ? i.document.body.scrollHeight : i.contentDocument.body.innerHeight + i.contentWindow.scrollMaxY;

      i.style.height = ih + 5 + "px";

}

</script>

 

<iframe name="bodyframe" src="privacypolicyu.htm" height="680" width="758" SCROLLING=NO frameborder="0"  onload="resizeIframe(this)"> 

Open in new window

0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
Well at least the page is displaying, but in firefox the iframe is only 1/2 the size of the real page size. So is it possible that IFrames only fo down so far anyway? The web page the Iframe is loading really is like 2 web pages long.
0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
Its still constrained to the heigth width dimensions in the iframe statement. If you put the words "test" under the iframe, it never leaves the same position. The size of the iframe is always the same.
0
 
LVL 16

Accepted Solution

by:
sh0e earned 500 total points
Comment Utility
Ya, I made another goof.  This time for real.  I commented it and everything to make sure I was using the working version.  I really need a better editor.

This one will work.
<script type="text/javascript">

function resizeIframe(i) {

    if(i.Document) //IE

		i.style.height = i.Document.body.scrollHeight;

	else if(i.contentWindow){

		if(i.contentWindow.innerHeight && i.contentWindow.scrollMaxY) //FF

			i.height = i.contentWindow.scrollMaxY + i.contentWindow.innerHeight;

		else if(i.contentWindow.document.height) //WebKit

			i.height = i.contentWindow.document.height;	

		else //all else fails

			i.height = i.contentWindow.document.body.scrollHeight;

	}

}

</script>

<iframe src="test.html" onload="resizeIframe(this)" scrolling="no"></iframe>

Open in new window

0
 
LVL 16

Expert Comment

by:sh0e
Comment Utility
I didn't realize I was testing two separate versions of my code in FF and IE, one that worked in each browser.
So I ended up posting different code that only work for one browser.
So I just junked the whole thing and rewrote it again verbosely.
0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
In FF--> the Iframe goes the whole length of the page (yeah!) BUT its cutoff at 1/2 its width

in IE-->doesn't work at all

0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
!! Update, I manually set the width and now it works *great*in FF - no prob.

However in IE, doesn't work.
0
 
LVL 16

Assisted Solution

by:sh0e
sh0e earned 500 total points
Comment Utility
Sigh.  IE7 right?
Add this to resizeIframe().  The style height: 25px is confusing IE7.
if(i.Document) aa.contentWindow.document.getElementById('content3').parentNode.style.height="auto";

Open in new window

0
 

Author Comment

by:Wanderinglazyeye
Comment Utility
Well, not at least IE shows something and FF is working correctly.

But IE is still not rolling it all the way out.

But that begs a bigger question, whether to use a resizing script at all. It seems its prone to malfunction and a browser upgrade may throw it into oblivion for your site. I am inclined to just fix the iframe height at a a standard at this point just out of concern for future functionality. What say you?

0
 
LVL 16

Assisted Solution

by:sh0e
sh0e earned 500 total points
Comment Utility
I would recommend you do that, or at least until a standard is agreed on for scrollHeight and company.
On the upside IE8 appears to work with this code.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now