Connecting Tech Pros Worldwide Forums | Help | Site Map

Cross domain iframe dynamic height change issue.

Newbie
 
Join Date: Aug 2008
Posts: 1
#1: Aug 20 '08
HI,
I am trying to display the content of a iframe in a div tag so that I can control the size of the display dynamically. The problem here is that the domain are different for parent window and the iframe content.

Code :
=====
Expand|Select|Wrap|Line Numbers
  1. var x=document.getElementById('myIFrame');
  2.  
  3. try{
  4.     x = x.contentWindow.document.body.innerHTML
  5. }catch (e){
  6. alert(e.message); 
  7. }
  8.  
I am getting a "Access denied" exception. Is there a work around for the issue.

Please help.

Thanks
Sreenath
[removed email]

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Aug 20 '08

re: Cross domain iframe dynamic height change issue.


To get the content, the only workaround is to serve it from your own domain using a proxy.
Newbie
 
Join Date: Feb 2009
Posts: 2
#3: Feb 5 '09

re: Cross domain iframe dynamic height change issue.


Quote:

Originally Posted by acoder View Post

To get the content, the only workaround is to serve it from your own domain using a proxy.


Hi,

How exactly does this work?

I am hosting a web-site that is supposed to be shown in a great number of different sites, via an iframe. So the problem is really on the receiver's end: they would want to setup their iframe so that it receives our dynamic content with automatic height.

Is it possible for me to teach all of these receivers how to implement the workaround you mention? Or do you reckon the fix is too complicated, and they have to settle for a fixed height (a very sub-optimal solution)?

Any answers welcome. Also: if I have not provided enough information, tell me, and I'll expand on it.

Thanks. Erik
Newbie
 
Join Date: Feb 2009
Posts: 2
#4: Feb 5 '09

re: Cross domain iframe dynamic height change issue.


Hi,

my task with the iframe seems difficult, from googling the issue.

Therefore, I am trying to think workarounds.

One possibly important issue here, is that the content that is produced on my site, will ONLY be used by other sites using IFRAME. That means, I can do whatever I want with the pages that are going to show in the iframe windows (except, due to contant issues, making them the same height...)

What I'm thinking is:

Is it possible to set up some kind of service, that automatically starts when a page is called for at my server, and first feeds some information to the recipient (i.e. document heigth). THen the recipient would use this information when setting up the page with the iframe, thus being able to set the correct iframe height?

Dunno if this makes sense, as I am not too familiar with the technicalities here, but if you need more information, let me know.

Thanks,

Erik
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Feb 7 '09

re: Cross domain iframe dynamic height change issue.


There's a few workarounds based on the fragment identifier or using an extra iframe. They would usually involve some sort of collaboration between the two domains. One way you could get it to work is if you have an iframe within your page content that has the same domain as the parent domain. The other is described here.
Reply