Skip to main content

@rtorcato/browser-common / window

window

Functions​

openWindow()​

openWindow(url, target?, features?): Window | null

Defined in: window/index.ts:13

Opens a new browser window or tab with the given URL.

Example​

import { openWindow } from '@rtorcato/browser-common/window'
openWindow('https://example.com', '_blank')

Parameters​

url​

string

The URL to open.

target?​

string = '_blank'

The target window name (e.g., '_blank', '_self').

features?​

string

Optional features string (e.g., 'width=600,height=400').

Returns​

Window | null

The window object or null if blocked.


closeWindow()​

closeWindow(): void

Defined in: window/index.ts:29

Closes the current browser window (if allowed).

Example​

import { closeWindow } from '@rtorcato/browser-common/window'
closeWindow()

Returns​

void


focusWindow()​

focusWindow(): void

Defined in: window/index.ts:41

Focuses the current browser window.

Example​

import { focusWindow } from '@rtorcato/browser-common/window'
focusWindow()

Returns​

void


blurWindow()​

blurWindow(): void

Defined in: window/index.ts:53

Blurs (removes focus from) the current browser window.

Example​

import { blurWindow } from '@rtorcato/browser-common/window'
blurWindow()

Returns​

void


scrollToTop()​

scrollToTop(behavior?): void

Defined in: window/index.ts:66

Scrolls the window to the top.

Example​

import { scrollToTop } from '@rtorcato/browser-common/window'
scrollToTop('smooth')

Parameters​

behavior?​

ScrollBehavior = 'auto'

The scroll behavior ('auto' or 'smooth').

Returns​

void


scrollToBottom()​

scrollToBottom(behavior?): void

Defined in: window/index.ts:79

Scrolls the window to the bottom.

Example​

import { scrollToBottom } from '@rtorcato/browser-common/window'
scrollToBottom('smooth')

Parameters​

behavior?​

ScrollBehavior = 'auto'

The scroll behavior ('auto' or 'smooth').

Returns​

void


reloadWindow()​

reloadWindow(): void

Defined in: window/index.ts:92

Reloads the current browser window.

Example​

import { reloadWindow } from '@rtorcato/browser-common/window'
reloadWindow()

Returns​

void


getWindowSize()​

getWindowSize(): object

Defined in: window/index.ts:105

Gets the current window size.

Example​

import { getWindowSize } from '@rtorcato/browser-common/window'
const { width, height } = getWindowSize()

Returns​

object

The window's width and height.

width​

width: number

height​

height: number


onWindowResize()​

onWindowResize(callback): () => void

Defined in: window/index.ts:120

Adds a listener for window resize events.

Example​

import { onWindowResize } from '@rtorcato/browser-common/window'
const off = onWindowResize(() => console.log(window.innerWidth))
off()

Parameters​

callback​

() => void

The callback to run on resize.

Returns​

A function to remove the event listener.

() => void