承接 webcito/iframe-resizer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webcito/iframe-resizer

Composer 安装命令:

composer require webcito/iframe-resizer

包简介

A JavaScript library for dynamic iframe resizing and communication.

README 文档

README

A lightweight JavaScript library for seamless iframe communication and automatic resizing.

Features

  • Automatic iframe height adjustment in the parent page
  • Optional iframe width adjustment
  • Two-way communication between parent and child frames
  • Scroll position synchronization
  • Custom event handling
  • Ready-state detection
  • Origin validation for parent and child messages
  • Configurable logging
  • Singleton pattern in a child frame

Installation

Add both scripts to your project:

<!-- In parent page -->
<script src="/dist/iframe-resizer-parent.min.js"></script>

<!-- In child page -->
<script src="/dist/iframe-resizer-child.min.js"></script>

Demo

Open demo/index.html in a browser or serve the project directory locally:

php -S localhost:8000

Then visit http://localhost:8000/demo/.

Usage

Parent Page

Basic setup:

const resizer = new IFrameResizer('#myIframe', {
    targetOrigin: 'https://child-domain.com',
    log: true,
    onResize: (width, height) => {
        console.log(`Iframe resized to ${width}x${height}`);
    }
}).onReady(() => {
    console.log('Iframe is ready!');
});

By default, the parent script applies the reported child height to the iframe element. Use autoResize: false if you only want to receive resize events without changing iframe styles.

Resize width as well as height:

const resizer = new IFrameResizer('#myIframe', {
    targetOrigin: 'https://child-domain.com',
    resizeWidth: true
});

Advanced usage with custom messages:

const resizer = new IFrameResizer('#myIframe', {
    targetOrigin: 'https://child-domain.com',
    log: true
});

// Handle custom messages
resizer.onMessage('customEvent', (payload) => {
    console.log('Custom event received:', payload);
});

// Send message to child
resizer.sendMessage('updateContent', {data: 'Hello Child!'});

Child Page

Basic setup:

window.IFrameResizer.create({
    targetOrigin: 'https://parent-domain.com',
    log: true
});

The child script waits until document.body is available, registers listeners, sends an initial forced resize event, and then sends a ready event.

Advanced usage with custom messages:

const resizer = window.IFrameResizer.create({
    targetOrigin: 'https://parent-domain.com',
    log: true
});

// Handle custom messages
resizer.onMessage('updateContent', (payload) => {
    console.log('Update received:', payload);
});

// Send message to parent
resizer.sendMessage('customEvent', {data: 'Hello Parent!'});

Configuration Options

Parent Options

Option Type Default Description
targetOrigin string '*' Allowed child origin for received and sent messages
autoResize boolean true Automatically apply child height to the iframe
resizeWidth boolean false Also apply child width to the iframe
log boolean false Enable console logging
onResize function null Callback for resize events
onScroll function null Callback for scroll events

Child Options

Option Type Default Description
targetOrigin string '*' Allowed parent origin for received and sent messages
log boolean false Enable console logging
resize boolean true Enable resize tracking and resize messages
scroll boolean true Enable scroll tracking

API Reference

Parent Methods

  • onReady(callback): Register callback for iframe ready state
  • onMessage(type, callback): Register custom message handler
  • sendMessage(type, data): Send a message to child iframe
  • destroy(): Clean up event listeners

Child Methods

  • window.IFrameResizer.hasParent(): Check if the script is running inside an iframe
  • onMessage(type, callback): Register custom message handler
  • sendMessage(type, data): Send a message to parent
  • destroy(): Clean up instance and listeners

Events

Built-in Events

  • ready: Sent when child iframe is initialized
  • resize: Triggered on size changes and once during child initialization
  • scroll: Triggered on scroll position changes

Custom Events

You can define and handle custom events using onMessage() and sendMessage().

Security

For production use, set targetOrigin on both parent and child instead of using the default '*'. Messages from other origins are ignored when a concrete origin is configured.

Browser Support

  • All modern browsers (Chrome, Firefox, Safari, Edge)
  • Requires ResizeObserver support for automatic resize tracking (or polyfill)
  • Requires postMessage support

License

MIT License

Contributing

Feel free to submit issues and pull requests.

webcito/iframe-resizer 适用场景与选型建议

webcito/iframe-resizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「javascript」 「library」 「communication」 「iframe」 「Resizer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 webcito/iframe-resizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webcito/iframe-resizer 我们能提供哪些服务?
定制开发 / 二次开发

基于 webcito/iframe-resizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 69
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-16