npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ohkit/react-iframe

v0.0.2

Published

iframe封装,replace变更src,避免干扰主页面history

Downloads

182

Readme

@ohkit/react-iframe

iframe封装,replace变更src,避免干扰主页面history

安装

npm install @ohkit/react-iframe

特性

  • 🔄 使用 location.replace() 替换 URL,避免干扰主页面历史记录
  • ⚡ 智能加载状态管理,仅在必要时重新加载资源
  • 🎯 支持同源 iframe 的 hashchange 事件监听
  • 📱 响应式设计,自适应容器大小
  • 🎨 内置加载状态提示
  • 🔧 TypeScript 支持,完整的类型定义

使用

基础用法

import { ReactIframe } from '@ohkit/react-iframe';
import '@ohkit/react-iframe/dist/index.css';

function App() {
  return (
    <div style={{ width: '800px', height: '600px' }}>
      <ReactIframe src="https://example.com" />
    </div>
  );
}

带加载回调

function App() {
  const handleLoadStart = () => {
    console.log('开始加载');
  };

  const handleLoadEnd = () => {
    console.log('加载完成');
  };

  return (
    <ReactIframe 
      src="https://example.com"
      onLoadStart={handleLoadStart}
      onLoadEnd={handleLoadEnd}
    />
  );
}

自定义样式

function App() {
  return (
    <ReactIframe 
      src="https://example.com"
      className="custom-iframe"
      style={{ border: '2px solid #ccc' }}
    />
  );
}

API

Props

| 属性 | 类型 | 默认值 | 说明 | |------|------|--------|------| | src | string | - | 必需,iframe 的源地址 | | iframeName | string | - | iframe 名称,会作为查询参数添加到 URL 中 | | className | string | '' | 容器的自定义类名 | | onLoadStart | () => void | - | 开始加载时的回调函数 | | onLoadEnd | () => void | - | 加载完成时的回调函数 | | onLoad | (event: React.SyntheticEvent<HTMLIFrameElement>) => void | - | iframe 加载完成的原生事件回调 | | children | ReactNode | '你的浏览器不支持iframe' | iframe 的后备内容 |

继承属性

ReactIframe 组件继承了所有标准的 HTMLIFrameElement 属性,包括但不限于:

  • width (默认: '100%')
  • height (默认: '100%')
  • frameBorder (默认: 0)
  • allowFullScreen
  • sandbox
  • loading
  • 等等...

工作原理

URL 替换策略

组件使用 location.replace() 方法来更新 iframe 的源地址,而不是直接修改 src 属性。这样做的好处是:

  • 不会在浏览器历史记录中产生新条目
  • 避免用户点击后退按钮时意外回到 iframe 的上一个页面
  • 提供更流畅的用户体验

智能重载

组件会检测 URL 变化的类型:

  • 仅 hash 变化:不会重新加载,直接更新
  • origin、pathname 或 search 变化:会显示加载状态并重新加载资源

同源支持

对于同源的 iframe,组件会自动监听内部的 hashchange 事件,便于与 iframe 内容进行交互。

许可证

ISC

相关链接