Solved

Iframe resizing problem in Firefox X

Posted on 2008-10-18
7
540 Views
Last Modified: 2012-05-05
Hi experts,

I am building a web site that uses Iframes. In IE, there is no problems resizing the iframe by using a javascript triggered by a "body onload" call function.

The problem is, in firefox - nada ! it's just not working and I can't figure how to adapt the code in order to make it work !

Here is what I have in my head portion of the page that goes in the iFrame.

<script type="text/javascript">
function resizeIframe() {

      // Must launched on the body onload event handler for IE
      // Use document.documentElement if you are in Compat mode
      i = parent.document.getElementById(window.name)
      iHeight = document.body.scrollHeight
      i.style.height = iHeight + 5 + "px"
}
</script>

This is my trigger

<body onLoad="redim()">

And this is my iframe

<iframe src="myform.asp" id="MainBody" name="MainBody" style="overflow-x:hidden;width:492px;height:auto;" frameborder=0 allowtransparency="true" scrolling="no"> </iframe>

Any suggestion ?
0
Comment
Question by:SirTKC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:sh0e
ID: 22749222
That code doesn't appear as if it would work in any browser.
Why are you referring to the parent in the parent page?
That script should be inside the iframe.

The below code is the closest I could get to what it seems you want.
test.html is the parent
testt.html is the iframe
--test.html--
<script type="text/javascript">
function resizeIframe(name) {
 
      // Must launched on the body onload event handler for IE
      // Use document.documentElement if you are in Compat mode
      i = parent.document.getElementById(name)
      iHeight = i.document.body ? i.Document.body.scrollHeight : i.contentDocument.body.scrollHeight
	  alert(iHeight);
      i.style.height = iHeight + 5 + "px"
	  
}
</script>
 
This is my trigger
 
<body onLoad="">
 
And this is my iframe
 
<iframe src="testt.html" id="MainBody" name="MainBody" style="overflow-x:hidden;width:492px;height:500;" frameborder=0 allowtransparency="true" scrolling="no"> </iframe>
 
Any suggestion ?
 
--testt.html--
<body onload="parent.resizeIframe(window.name);">
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
</body>

Open in new window

0
 
LVL 16

Accepted Solution

by:
sh0e earned 500 total points
ID: 22749234
Sorry, copy/pasted the wrong files above.  Been doing that a lot lately.
---test.html---
<script type="text/javascript">
function resizeIframe(name) {
      // Must launched on the body onload event handler for IE
      // Use document.documentElement if you are in Compat mode
      i = parent.document.getElementById(name)
      iHeight = i.document ? i.Document.body.scrollHeight : i.contentDocument.body.scrollHeight
      alert(iHeight)
      i.style.height = iHeight + 5 + "px"
}
</script>
This is my trigger
 
<body onLoad="">
 
And this is my iframe
<iframe src="testt.html" id="MainBody" name="MainBody" style="overflow-x:hidden;width:492px;height:500;" frameborder=0 allowtransparency="true" scrolling="no"> </iframe>
 
Any suggestion ?
 
---testt.html---
<body onload="parent.resizeIframe(window.name);">
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
Any suggestion ?<br>
</body>

Open in new window

0
 
LVL 3

Author Comment

by:SirTKC
ID: 22749321
Hi sh0e,

It works well just like before in IE.
I like the alert that returns the iFrame height in this JavaScript.
But what's curious is that I get "883" (certainly pixels) in IE and only "19" in Firefox !?

You see, resizing is not working... :-/

I have read on certain forums that dynamic content such as ASP or PHP seem to be very problematic with this approach. Also, it as to be a content that is located on the same domain (which is is this case). Do you think it has anything to do with it ?

Thanks for your help on this one.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:sh0e
ID: 22749374
What version of firefox are you using?  I tested the code on FF 3.0.3, WebKit, IE6.
0
 
LVL 3

Author Comment

by:SirTKC
ID: 22749449
I do have Firefox 3.0.3 But like I said, the content of the Iframe is an ASP form approx. 1500 px height.
0
 
LVL 16

Expert Comment

by:sh0e
ID: 22749469
Does my sample code (verbatim) render properly on your browsers?  It should work under FF 3.0.3.
I may need to see more of your code, or a demo site preferably, to help you.
0
 
LVL 3

Author Closing Comment

by:SirTKC
ID: 31507448
Hi sh0e

Yes your piece of code is working just fine. Matter of fact, I am using it now on all our website. The credit is yours !

In order to get it work smooth and easy, I had to remove this "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">" from all pages who's displayed in the iFrame

And boom voila !!

Points are yours !
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET - Why is accordion not working? 3 49
Validating Date Part2 2 27
Anyone familiar with PhotoSwipe? 3 17
Aspx calendar pop up control 3 28
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 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