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
Simplicity :
I figured out another solution after some experimenting. I originally tried the code marked as 'best answer' to this question and it didn't work. My guess is because my iframe in my program at the time was dynamically generated. Here is the code I used (it worked for me):
Javascript inside the iframe that is being loaded:
Here is the html for the iframe:
Here is all the code within my iframe:
I have done testing in chrome and a little in firefox (in windows xp). I still have more testing to do, so please tell me how this works for you.
I know the post is old, but I believe this is yet another way to do it. I just implemented on my code. Works perfectly both on page load and on page resize:
For angularjs directive attribute:
Notice the percentage, i inserted it so that you can counter scaling usually done for iframe, text, ads etc, simply put 0 if no scaling is implementation
one-liner solution for embeds: starts with a min-size and increases to content size. no need for script tags.
Here is a cross-browser solution if you don't want to use jQuery: