open-window
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

open-window

A library for easy inter-window communication encapsulated in Window:open() mehtod.

Installation

npm i open-window --save

Demo

demo

Import

ES5 Imports

import { openWindow, OpenerWindow } from 'open-window';

Browserify

<!--publishes one browserified bundles inside the dist/ folder: -->
<script src="lib.iife.js"></script> 
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/open-window/dist/lib.iife.js"></script> 

Usage

In opener.html

import { openWindow } from 'open-window';

/* like as window.open*/
openWindow('http://localhost:5173/popup.html', 'popup,width=550,height=200,top=100').then(popupWindow => {
  popupWindow.addCloseEventHandler(() => {
    console.log('popupWindow closed');
  });
  popupWindow.addMessageEventHandler(msg => {
    if (msg.type === 'hello') {
      console.log(msg.value);
      popupWindow.sendMsg({ type: 'hello', value: 'from opener.html' });
    }
  });
});

In popup.html

import { OpenerWindow } from 'open-window';

OpenerWindow.sendMsg({
  type: 'hello',
  value: 'from popup.html'
});

OpenerWindow.addMessageEventHandler(msg => {
  if (msg.type === 'hello') {
    console.log(msg.value);
    OpenerWindow.closePopup();
  }
});

API Reference

function return
openWindow(url[,feature]) PopupWindow
OpenerWindow.sendMsg void
OpenerWindow.closePopup void
OpenerWindow.addMessageEventHandler void
OpenerWindow.removeMessageEventHandler void
OpenerWindow.addCloseEventHandler void
OpenerWindow.removeCloseEventHandler void
PopupWindow type
popupWindow.sendMsg function
popupWindow.close function
popupWindow.addMessageEventHandler function
popupWindow.removeMessageEventHandler function
popupWindow.addCloseEventHandler function
popupWindow.removeCloseEventHandler function
popupWindow.url string
popupWindow.closed boolean

License

MIT License.

Package Sidebar

Install

npm i open-window

Weekly Downloads

4

Version

0.0.2

License

MIT

Unpacked Size

18.9 kB

Total Files

7

Last publish

Collaborators

  • strive087