1.1.8 • Published 1 year ago

@ce1pers/window-helpers v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@ce1pers/window-helpers

Simple web application window screen hook.

Installation

npm

npm i @ce1pers/window-helpers

yarn

yarn add @ce1pers/window-helpers

Usage

Use Popup

// Import hook.
import { useWindow } from "@ce1pers/window-helpers";

// Declare use popup hook.

type SendMessageType = "connection" | "submit";

const { open, sendMessage } = useWindow({
  onMessageCallback,
});
const TARGET_URL = "http://localhost:5555";

// Open new window as popup.
open({
  targetOrigin: TARGET_URL,
  windowTarget: "_blank",
  callback: openPopupCallback,
  width: 400,
  height: 400,
});

setInterval(() => {
  sendMessage<SendMessageType>({
    to: "targetOrigin",
    type: "connection",
  });
}, 1000);

function onMessageCallback(event: MessageEvent) {
    if (event.origin !== TARGET_URL) return;
  // Write process what execute when received message from other window.
}

function openPopupCallback() {
  // Write process what you want when opened a new window.
}
1.1.1

2 years ago

1.1.0

2 years ago

1.1.8

1 year ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago