views:

308

answers:

1

Hi,

I have a rails app running on port 3000. The page in question has an iframe and I need to resize it depending on the height of the content loaded in the iframe.

<iframe id="ifrm_col3" name="ifrm_col3" frameborder="0" 
src="<%=invite_path(@invite.alias)%>" 
onload="util.resize_iframe('ifrm_col3');"></iframe>

The resize function is here:

util.resize_iframe = function(frame_id) {
  var h = document.getElementById(frame_id).contentWindow.document.body.scrollHeight;
  document.getElementById(frame_id).height = h; 
}

After the iframe loads, I see this error in FireBug:

Error: Permission denied for <http://192.168.0.157&gt; to get property Window.document from <http://192.168.0.157:3000&gt;.
Source File: http://192.168.0.157:3000/javascripts/application.js?1268327481
Line: 84

HTML rendered for the iframe looks like this:

<iframe id="ifrm_col3" name="ifrm_col3" frameborder="0" 
            src="/invite/my-invite-1" 
            onload="util.resize_iframe('ifrm_col3');"></iframe>

The src of iframe is a relative path, but I'm not sure why the port info from the parent page is not retained. Is there any workaround to this problem?

I tried creating a function in the parent page and calling it from the iframe, but ran into the same issue.

Due to extra features in the site, I need to stick to port 3000 for the rails app.

Any suggestion is appreciated.

+2  A: 

Are you quite sure that <%=invite_path(@invite.alias)%> does, in fact, output a relative path? That nothing has resolved it (incorrectly) along the way? What does the actual output to the src attribute end up looking like?

T.J. Crowder
@T.J. Crowder, thanks for the reply. Yes, I updated the post with HTML snippet.
Grnbeagle
@Grnbeagle: I can't see any reason the browser should be (mis)interpreting that as being on port 80 instead of 3000, provided the page the iframe is in is served via port 3000.
T.J. Crowder
@T.J. Crowder, you're right. This shouldn't happen. It's my bad. The page in the question uses a stomp client library which requires to set document.domain. I'm doing research on how to get around it. Thanks for your input though.
Grnbeagle
@Gmbeagle: `document.domain` -- why didn't I think of that?! Good luck with it.
T.J. Crowder