I have an iframe with a published Google Doc. The contents of that doc are subject to change, so I want to auto adjust the height of the iframe based on its content. I found some solutions for this, but they all require access to the head of the child document. Does anyone have an idea on how to do this?
You can view an excerpt of the code I use below:
#faq{
height: 800px;
overflow: hidden;
position: relative;
width: 660px;
border-top: 1px solid #90C547;
border-bottom: 1px solid #90C547;
}
<div id="faq"><iframe id="faqif" src="https://docs.google.com/document/..../pub?embedded=true" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:900px;width:832px;position:absolute;top:-92px;left:-150px;right:0px;bottom:0px;z-index:0;" height="900px" width="832px"></iframe></div>
The bad news is that the cross domain policy will not let you do that in any way around. I spent a couple hours trying to work around, which included:
The best approach is to use an available library.
Download the ZIP from the following URL and follow the simple installation instructions written there.
http://davidjbradshaw.github.io/iframe-resizer/
It looks promising but I am not able to test it myself. Have a look at it and post comments if you need help.
Simple answer...you cant
(sorry)
The reason is due to the cross domain policy (more, info) you cant access the
iframe
child document and therefore ascertain itsheight
in order to resize theiframe
accordingly, simply putsource
[...]
source
And if you cant do this, you cant do what you want because there is no way of ascertaining the child document's height.
It seems the reason you want to do this is design related. As such, you may want to look at different ways to implement the content (iframe) within your site, the obvious one being that the natural restriction on height is browser viewport height, perhaps therefore make the
iframe
100% of the viewport (html, body) height? Although this will interfere with your design if there are other components on the page...but there are alternatives...theiframe
could:Be aligned to one side of the page with 100% height set
Be placed within a popup or modal window with 100% height/width
Be controlled (JS) to stretch with the parent window, perhaps with a fixed
bottom
Also remember that because this is a global restriction on this kind of content, users are not completely unused to seeing it so though it isnt an ideal design choice, it isnt necessarily one which will confuse/suprise visitors to your site.
i was having the same problem. Here is The solution You have to set the body 100% 100% widht height Then the iframe display block, 100% width 100%vh Here is the final code.. sry i dont know how to put the code tag xd
`body style="margin: 0px; padding: 0px; width: 100%; height: 100%;" div style="height: 100%; width: 100%; display: block;" iframe frameborder="0" style="height: 100vh; width: 100%; display: block;" width="100%" height="100%" src="https://docs.google.com/spreadsheets/d/1SizkrPE97j1TouBmohPjCj0ZB-MxYQtRSKotHyxT8Y8/edit#gid=0"/iframe div
Something similar has been asked here: Display full length of document for embed google document
The solution is to either use
<embed>
instead of<iframe>
or toGET
your document via CORS request and put it wherever you want. The latter also allows you to style/modify the content.There's no current way to do this.
You can, however, make the height a lot larger and hide the borders, this way the iframe scrollbar won't appear and the document will appear to be a part of your website.