window-open-promise
v1.1.32
Published
πͺ Promised Window.open();
Downloads
329
Maintainers
Readme
πͺ Promised Window.open();
.
Usage
π¦ Node
Install window-open-promise
as a dependency:
pnpm add window-open-promise
# or
npm install window-open-promise
# or
yarn add window-open-promise
Import it and use it:
import { windowOpenPromise } from "window-open-promise";
const windowOpen = windowOpenPromise(globalThis);
windowOpen({
url: "https://example.com", // URL is not required, you can open a blank window
top: 10,
left: 10,
})
.then(newWindow => {
newWindow.console.log("This will log in the new window.");
newWindow.addEventListener("beforeunload", _event => {
console.log("This will log when the new window is closed.");
});
})
.catch(_error => {
console.error("This will log if the new window can't be opened.");
});
π¦ Deno
Import window-open-promise
using the npm:
prefix, and use it directly:
import { windowOpenPromise } from "npm:window-open-promise";
const windowOpen = windowOpenPromise(globalThis);
try {
const newWindow = await windowOpen({
url: "https://example.com", // URL is not required, you can open a blank window
top: 10,
left: 10,
});
newWindow.console.log("This will log in the new window.");
newWindow.addEventListener("beforeunload", _event => {
console.log("This will log when the new window is closed.");
});
} catch (_error) {
console.error("This will log if the new window can't be opened.");
}
π Browser
Import window-open-promise
using esm.sh, and use it directly:
<script type="module">
import { windowOpenPromise } from "https://esm.sh/window-open-promise";
const windowOpen = windowOpenPromise(globalThis);
try {
const newWindow = await windowOpen({
url: "https://example.com", // URL is not required, you can open a blank window
top: 10,
left: 10,
});
newWindow.console.log("This will log in the new window.");
newWindow.addEventListener("beforeunload", _event => {
console.log("This will log when the new window is closed.");
});
} catch (_error) {
console.error("This will log if the new window can't be opened.");
}
</script>
Useful links
- π Documentation: TypeDoc generated documentation.
- β³ Changelog: List of changes between versions.
- β Tests Coverage: Coveralls page with tests coverage.