Adjust width and height of iframe to fit with content in it

前端 未结 30 2762
旧时难觅i
旧时难觅i 2020-11-22 02:09

I need a solution for auto-adjusting the width and height of an iframe to barely fit its content. The point is that t

30条回答
  •  滥情空心
    2020-11-22 02:36

    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:

    • Height and width resizing of the iFrame to content size.
    • Works with multiple and nested iFrames.
    • Domain authentication for cross domain iFrames.
    • Provides a range of page size calculation methods to support complex CSS layouts.
    • Detects changes to the DOM that can cause the page to resize using MutationObserver.
    • Detects events that can cause the page to resize (Window Resize, CSS Animation and Transition, Orientation Change and Mouse events).
    • Simplified messaging between iFrame and host page via postMessage.
    • Fixes in page links in iFrame and supports links between the iFrame and parent page.
    • Provides custom sizing and scrolling methods.
    • Exposes parent position and viewport size to the iFrame.
    • Works with ViewerJS to support PDF and ODF documents.
    • Fallback support down to IE8.

提交回复
热议问题