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
Solved

How can i auto resize the height in my IFRAME?

Posted on 2007-11-15
12
2,295 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

860 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