?
Solved

resizing an iFrame depending on cross-domain content

Posted on 2010-04-07
11
Medium Priority
?
311 Views
Last Modified: 2014-01-13
Hi.

I would like to resize an iFrame (height) depending on content (from another domain).  

I know it's possible as the website blogasty.com is doing it (just have a look at this URL:

http://blogasty.com/billet/359813-discussion-autour-de-l-avenir-des-digglike-sont-ils-appeles-a-mourir-ou-simplement-post

The bottom is an iFrame and the height is adjusting to the content height.

How he's doing it?

Thanks
0
Comment
Question by:jeff0191
  • 4
  • 3
  • 2
9 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 30099181
Where do you see it is resizing?

It has a width of 100% if that is what you mean

<iframe width="100%" height="1000px" frameborder="0" style="background-color: rgb(255, 255, 255); height: 566px;" src="..." id="globpage"></iframe>


0
 
LVL 3

Expert Comment

by:sushiguru
ID: 30103594
Try the snippet:

sg
<iframe id="my_iframe" src="MY_IFRAME_URL" width="100%" scrolling="no" onload="checkHeight();"></iframe>

<script type="text/javascript">

   function checkHeight() {
      h = document.getElementById('my_iframe').contentDocument.body.scrollHeight;
      document.getElementById('my_iframe').style.height = h;
   }

</script>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 30105610
I am pretty sure that will give you an access denied in most browsers
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
LVL 3

Expert Comment

by:sushiguru
ID: 30106225
Yes - if the iframe url is external to your site, in which case you're stuffed. (soz - just saw that in the question - url from another domain).

I'm not sure there is a way to do it using an iframe...

sg
0
 

Author Comment

by:jeff0191
ID: 30110270
If you go on the home page and click on any article, you'll see that the iFrame is effectively resizing depending on content.  And this content is on an external website.  

Also, when I looked in the js file (site.js) there's a function adapt() where I can see:

$('globpage').style.height = (document.viewport.getHeight()-marginsize)+'px';

Not sure what this doing but this function is called in the body onload event.  
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 30110818
Cool

I searched for viewport and found prototype calls and this (scroll down for the comment)
https://support.zendesk.com/entries/56734-uber-iframe-widgets
0
 

Author Comment

by:jeff0191
ID: 30112208
That's a cool script mplungjan, but that's not doing what I want (it does an iFrame act like a lightbox but not resizing depending on iFrame content).  But i'll definitely bookmark this page as it could be cool to use it some time :)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 30112661
so globpage is the ID of the iFrame
document.viewport must be the main document and not the iframe document.
So it is as far as I can see NOT resizing to the iframe content but resizing the iframe to the document containing the iframe
0
 

Accepted Solution

by:
jeff0191 earned 0 total points
ID: 30117827
Hey guys, I think I've finally found a solution.

Just look at this page:

http://www.amirharel.com/labs/it/res_iframe.html?iframe=yahoo.com

it's resizing depending on the content (just change the param in the URL to see it working).

I'll just explore what he did.  

Thanks for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

ASP.NET AJAX callbacks to web service are becoming very popular and unavoidable these days. The feel that the user gets when only a part of the page is updated without even hindering the UI is the advantage that the callbacks offer. The wait for the…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

607 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