Pop a new window React using window.open.
Inspired by David Gilbertson's article (must read, must follow).
- Only 3.3KB (that's 1.4 gzipped!).
- Support the full
window.open
api. - Built for React 16 (uses
ReactDOM.createPortal
). - Handler for blocked popups (via
onBlock
prop). - Center popups according to the parent window or screen.
-
npm install react-new-window --save
or
-
yarn add react-new-window
import React from 'react'
import NewWindow from 'react-new-window'
const Demo = () => (
<NewWindow>
<h1>Hi 👋</h1>
</NewWindow>
)
Properties | Type | Default | Description |
---|---|---|---|
url |
String |
`` | The URL to open, if specified any children will be overriden (more details on url ). |
name |
String |
`` | The name of the window (more details on windowName ). |
title |
String |
`` | The title of the new window document. |
features |
Object |
{} |
The set of window features (more details on windowFeatures ). |
onUnload |
Function |
undefined |
A function to be triggered before the new window unload. |
onBlock |
Function |
undefined |
A function to be triggered when the new window could not be opened. |
center |
String |
parent |
Indicate how to center the new window. Valid values are: parent or screen . parent will center the new window according to its parent window. screen will center the new window according to the screen. |
Made with :hearth: by Rubens Mariuzzo.