Solved

How can i auto resize the height in my IFRAME?

Posted on 2007-11-15
12
2,291 Views
Last Modified: 2013-11-19
hello.  I have a situation where i need to have an IFRAME auto size it's height based on the content that is loaded into it.  right now here is the IFRAME source in a file called, lets say, test.html:

<iframe id="ifrm" name="ifrm" src="http://www.remotesite.com/myfile.php" marginwidth="1" marginheight="1" width="510" height="707" border="0" frameborder="0">
Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe>

that file, "myfile.php" is on another server of mine and it will produce content varying in height etc etc so i'm wanting the file that contains the iframe code above to auto adjust it's height based on how much content is in the myfile.php file.  is this possible?  any known code to do that?
thank you!
0
Comment
Question by:linuxrox
  • 8
  • 4
12 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20289479
Try this:


<iframe name="iframe" src="home.htm" frameborder="0"

onload="this.style.height=parseInt(window.frames.iframe.document.body.scrollHeight)+50;"></iframe>

 

or 

 

<iframe name="iframe" src="home.htm" frameborder="0"></iframe>

<script>

window.frames[0].onload=function() {this.style.height=parseInt(window.frames.iframe.document.body.scrollHeight)+50;}

</script>

Open in new window

0
 

Author Comment

by:linuxrox
ID: 20289516
okay, i'll try that and get back...gotta reboot my server in a minute.
0
 

Author Comment

by:linuxrox
ID: 20290061
mplungjan:

for some reason i get "permission denied" or "access denied" : (
that shows up in status bar at lower left..javascript error.  why would that be you think?
would it be because the src="" is a remote file and not local?  
0
 

Author Comment

by:linuxrox
ID: 20290077
let me try again, think the "access denied" was from an onload even on my remote file....
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20290116
yes that is the reason.

You will need a proxy if you want to load from external source
0
 

Author Comment

by:linuxrox
ID: 20290141
yea i still get the permission error.  if i don't try and resize the frame all the content loads up just fine though.  so does it only have to do with resizing?  because otherwise everything loads up just fine.
how would a proxy work for doing this?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:linuxrox
ID: 20290215
the below works of course..but i'm giving it an actual number value instead of relying on
 parseInt(window.frames.iframe.document.body.scrollHeight)+50:


<iframe name="iframe" src="http://www.remotesite.com/test.php" frameborder="0"></iframe><script>window.frames[0].onload=function() {this.style.height=707;}</script>

Open in new window

0
 

Author Comment

by:linuxrox
ID: 20290223
code snippet didn't work:
<iframe name="iframe" src="http://www.remotesite.com/test.php" frameborder="0" onload="this.style.height=700;"></iframe>
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 20291258
You would prefix the url with a url of your own:

getremote.php?url=remotesite.com/test.php
0
 

Author Comment

by:linuxrox
ID: 20291440
okay are you saying something like this?:
<iframe name="iframe" src="localfile.php?url=http://www.remotesite.com/test.php" frameborder="0" onload="this.style.height=700;"></iframe>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20296725
Yes. And the localfile does a curl or something to grab the site
0
 

Author Closing Comment

by:linuxrox
ID: 31409332
Thanks.  Looks like to allow people to display my system on their site with an autoadjusting iframe height, they will have to include either a php or asp script that gets the url using curl or whatever asp uses to load the page locally from their host.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

747 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

9 Experts available now in Live!

Get 1:1 Help Now