iframes - auto resize to heigh of content?
I have built a page which has an iframe in it. I also have a page header and footer displayed on the page, shown by way of include file statements. The iframe is between the header and footer and is set to display a page not on my website.
The inserted page has hyperlinks on the page which the user can click, and thus the height of the content to be displayed changes.
Is it possible to set up the iframe so that it will auto size the frame window page to the size of the inserted page to be displayed, if it changes. I have currently had to set the height of the iframe very large so that it will display the biggest page of content that the user can display using the frame开发者_运维技巧 (800). The only problem with this is that most pages to be shown in the frame are only small, so for the most part users dont get to see the page footer.
One last point, I dont want to use a scroll bar to achieve the above.
Is it possible to do this, and if so how?
If the pages are on the same domain, it's relatively straight forward. If it's on a different domain, it can't be done without co-operation from the other sites.
The problem is that JavaScript is prevented from accessing frames/iframes from other domains. The solution is to have the iframed page create its own hidden iframe. The iframed page loads into its hidden iframe a specially crafted URL pointing to a page back on the original server. This hidden page detects the specially crafted URL, and parses it for data, such as the size of the iframe. Because this hidden iframe is on the same domain as the main page, it can access JavaScript in the main page by going parent.parent.thing.
For more information, google cross-domain iframe communication.
Yes it is possible. This might help.
Here is a demo
精彩评论