Getting the height of an iframe content in Javascript on the android browser
I am trying to make some javascript 开发者_如何学JAVAthat will automatically resize an iframe based on the height of the content in the iframe.
This from QuirksMode, implies that I can use clientHeight
. I am getting it this way: var innerHeight = ele.contentWindow.document.documentElement.clientHeight
, and then setting ele.height = innerHeight
.
On desktop Chrome this works perfectly and will make the iframe exactly fit the content. However on the default android 2.2 webbrowser, the iframe is not tall enough and some content from the bottom of the iframe is cropped. I've also tested it on iPhone (3 I think), and it behaves the same as the Android
Is there a better way to automatically adjust the height of the iframe to fit the content?
I am not sure of the exact code to use in this context, but Android has a great resource for best practices for developing for the mobile web here:
http://developer.android.com/guide/webapps/best-practices.html
and this may also help:
http://developer.android.com/guide/webapps/targeting.html
and of course it would be remiss to read what the W3C has to say here:
http://www.w3.org/TR/mobile-bp/
I know it's not like handing over code, but at least it's a start.
精彩评论