百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-popout

> 编程语言
开源

React popout 是一个包装 window.open 的 React 组件,可让您在浏览器弹出窗口中托管内容。

191 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

React popout 是一个包装 window.open 的 React 组件,可让您在浏览器弹出窗口中托管内容。

react-popout

React popout is a React component wrapping window.open allowing you to host content in a browser popup window.

npm install react-popout --save

Demo

To see it in action just go to http://jake.ginnivan.net/react-popout

Usage

Import with es6

import Popout from 'react-popout'

The usage is really simple. When the component is mounted the popup is open, and when it is unmounted the popup is closed.

javascript

  

To close the window programatically give the window a ref and use the closeWindow function.

props

title [required]

Title for popup window.

url [optional]

URL of the page to load intially. Often needed for css. about:blank will be used if not specified.

onClosing [optional]

Called when popout window is closed, either by user or by calling close.

options [optional]

Object representing window options. See the docs for reference.

Example: ``

By default 500px wide, 400px high and centered over the window hosting the react component.

You can also specify a function with signature (options, window) => { } to perform calculations. For example top is calculated with (o, w) => ((w.innerHeight - o.height) / 2) + w.screenY

window [optional]

Instead of using the window global, a window object can be passed in. It needs the following functions on it:

window.open(, , ); and return an object which looks like this:

{
  onbeforeunload: () => { },
  onload: () => { },
  close: () => { },
  document: {
    title: string,
    body: {
      appendChild: (ele) => { }
    }
  }
}

This can be used if you need to intercept the calls and do something else.

containerId [optional]

Assigns an Id to the container that will be injected in the popup window document.body, defaults to popout-content-container, useful for cascading styles.

Example:

// input

  

// output in new window:

onError [optional]

Provides a callback incase the window wasn't opened, usually due to a popout blocker within the browser.

Example:

// input
 {}}>
    ...

Example hosting component

javascript
class HostingComponent {
  constructor(props) {
    super(props);
    this.popout = this.popout.bind(this);
    this.popoutClosed = this.popoutClosed.bind(this);
    this.state = { isPoppedOut: false };
  }

  popout() {
    this.setState({isPoppedOut: true});
  }

  popoutClosed() {
    this.setState({isPoppedOut: false});
  }

  render() {
    if (this.state.isPoppedOut) {
      return (
        
          

        
      );
    } else {
      var popout = 
      return (
        

        
      );
    }
  }
}

The popped out content can have props set and will render just as you would expect a normal React component to render.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言