Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

How does an iframe know how far to scroll?

Jul 31, 2013 6:05AM PDT

I'm developing a web app and have run across a bump on the native web browser on a tablet running Android 4.1.1. No idea if it's a more widespread issue as I'm low on testing devices.

For simplicity's sake, consider the following:

There is a page that contains another in an iframe. The only starting content on the child page is two buttons. Pressing the first button will reveal a div which was previously hidden. Once visibly, pressing that button will hide the div again. The same goes for the second button for a second div.

Here's what it does (and what you would expect):

If the first div's contents are too large for the iframe, the iframe realizes this and it gives itself a scrollbar when the div is revealed. After hiding it, the iframe realizes it doesn't need to be scrollable anymore and the page is seemingly back where it started.

Here's what it does and what the problem is:

After opening and closing the div mentioned above, you click the second button to reveal the second div BUT the content of the second div is even bigger than the first and now the iframe only scrolls to where the content from the first div stopped. =[

I've seemingly looked all over and can find no solutions on this. No cross-domain issues; it still occurs when the pages are local and in the same folder. I've decided that it's just a bug and something that should work so now I'm just trying to see if there's anything along the lines of javascript snippet that I can use to force the iframe to re-evaluate how far it needs to scroll.

Any help would be much appreciated as I've been pulling my hair out over this for a while.

Discussion is locked

- Collapse -
Answer
Neat issue.
Jul 31, 2013 6:20AM PDT

Not an answer but I ran into other browser issues on android but remember it's NOT an android issue but a browser issue. To test out if we did it right we did 2 things.

1. Try it on the Chrome Browser (PC and Android)
2. Test our code at http://validator.w3.org/

Hope this helps.
Bob

- Collapse -
Good pointers!
Jul 31, 2013 6:39AM PDT

Hi Bob.

I've been using the native browser for all of my testing so far and unfortunately, I'm stuck with needing to make it work there. My code is eventually going to be fed through PhoneGap which works by wrapping the html in a webview. So if it works in Chrome, that's great, but it still won't work in the end-product app.

Thanks for your input, though!

- Collapse -
Bad pointers.
Jul 31, 2013 7:44AM PDT

Sorry but there are too many busted browsers in too many 99 buck and under tablets.

Does this (unknown?) browser pass browser tests? Here's one of many out there.

-> http://www.acidtests.org/
-> More out there. Google Acid Browser Tests

- Collapse -
Answer
All you can do.
Jul 31, 2013 6:43AM PDT

1. Play with the different options mentioned in http://www.w3schools.com/tags/tag_iframe.asp
2. Study what the html-standard http://www.w3.org/TR/REC-html40/ says about how this works. If it is not prescribed it's explicitely or implicitely left to the agent (i.e. the browser) how to handle the it.

It would be interesting to read your findings. And, of course, you can suggest mozilla to include your changes to their open source browser in their next version, so it works better (according to you, and maybe also according to their policy team that determines how the browser works on points that are not prescribed in the standard). That's the nice thing about open-source.

For the javascript options to handle an iframe a little bit of googling gave http://www.developerfusion.com/thread/33979/creating-iframe-through-javascript/ showing how to set the size of an iframe and http://javascript.info/tutorial/frames-and-iframes how to reference an existing frame. Maybe that can be used to set the size explicitely in coding executed by the button.

But let me suggest a simple work-around: add a few iterations of <br>  at the bottom of the smaller div to make it exactly as big as the larger one.
Or don't work with iframes, just with div's that are hidden and shown inside the page itself. That's only cumbersome if the same 'subpage' is used in iframes in different 'main' pages, although some form of include should neatly handle that also.

Kees