IFRAMEs Automagically Fit Their Content on iOS
The result of a recent struggle with IFRAMEs on iOS Safari is an interesting discovery: IFRAMEs can expand to fit their (content documents) content without any JavaScript. Even cross-domain! There are two important notes:
- Adding
scrolling="no"
attribute to IFRAME disables this behavior. - It only works with dynamically changed content: the IFRAME will not fit the initial content.
Example code:
content.html:
Click the button and see the magic! Try example code online from your iOS device.
Tested on iOS4 and iOS5, does not work in any other browser I tried. Could not find any relevant documentation on this behavior except a StackOverflow post.