0.0.2 • Published 2 years ago
open-window v0.0.2
Installation
npm i open-window --saveDemo
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.