views:

397

answers:

3

I have tried....
I have tried a lot many things...
Even searched Yahoo! , Google and Bing...

Why oh! why does the code not reveal...
I just want to complete it and put the quality seal....

External frame resizing...
is so f'king tensionizing.....

I need to find the solution....
before in my head it causes more pollution....

OK, Enough of useless poetry...

Normal page structure :-

<body>
    <div>
        blah blah
    </div>
    <iframe>
        this is an iframe whose source is modified frequently and point to various domains. This needs to be resized dynamically according to the src page it points to right now ....
    </iframe>
</body>

I tried many codes, including the "contentWindow.....scrollHeight" thing, but as it is an external frame, the brower blurts something like "Security warning. access to frame with external frame not allowed "

Read somewhere that this can be accomplished using framesets ?

Any help will be highly appreciated.

A: 

You should simply change the style of the iframe object. If you are using jQuery ( you should :D ), it's as simple as $('iframe').height(321).width(321);

if not: document.getElementByID('iframeID').style.height = "321px"; document.getElementByID('iframeID').style.width = "321px";

If you only know the size needed in the url of the loaded frame, you can also access the parent via : window.parent

if you expose a function at the parent called changeIframeSize(height, width), you can call that from the frame with:

window.parent.changeIframeSize(312,321);

HTH,

Erik

Erik
Thank you for the reply.I got what you meant in your reply and tried to implement the second part (the "window.parent.changeIframeSize(312,321);" part)I'm faced with a new roadblock .How to create a call back in the child frame so that when the child frames source is changed, the function is automatically called (something like onSourceChange() ) ?Please note that the called source is completely external and I have no control over it. Moreover, I do not want this to be on the server side....Trying out implementing it via Ajax. If it is successfull, will post it here later.
Nope, turns out even Ajax has cross domain restrictions !! So that is out of the question....Running out of options now....
A: 

To get around the same origin policy, you'll need each page you iframe to have on it an iframe containing a helper page on your site.

Why does this work?

I've explained it in a bit more detail here, but basically the browser security model allows pages to pass information to two types of site:

  • sites which they have iframed

  • sites on the same domain

If you get the page you want iframed to pass details like it's height to the helper page you've had them iframe, then that page can send that information back to your main page, as it's on the same domain.

The above is, of course, only a viable solution if the pages you are iframing agree to include your helper file, otherwise what you're doing isn't really possible I'm afraid.

ConroyP
A: 

Thank you ConoroyP & Erik for your replies.

This can be accomplished by sending a 302:Moved Temporarily header that redirects the frame to the external source required. Morever, you need to use the frameset and frame tags instead of the iframe tag

thanks