I need a solution for auto-adjusting the width
and height
of an iframe
to barely fit its content. The point is that the width and height can be changed after the iframe
has been loaded. I guess I need an event action to deal with the change in dimensions of the body contained in the iframe.
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
If you can control both IFRAME content and parent window then you need the iFrame Resizer.
This library enables the automatic resizing of the height and width of both same and cross domain iFrames to fit their contained content. It provides a range of features to address the most common issues with using iFrames, these include:
This is how I would do it (tested in FF/Chrome):
This is how I did it onload or when things change.
If the iframe content is from the same domain this should work great. It does require jQuery though.
To have it resize dynamically you could do this:
Then on the page that the iframe loads add this:
If the content is just a very simple html, the simplest way is to remove the iframe with javascript
html:
javascript:
This is a solid proof solution
the html