Skip to content
On this page

useWindowFocus

Category
Last Changed
3 months ago

Reactively track window focus with window.onfocus and window.onblur events.

Demo

💡 Click somewhere outside of the document to unfocus.

Usage

import { useWindowFocus } from '@vueuse/core'

const focused = useWindowFocus()
import { useWindowFocus } from '@vueuse/core'

const focused = useWindowFocus()

Component

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.
<UseWindowFocus v-slot="{ focused }">
  Document Focus: {{ focused }}
</UseWindowFocus>
<UseWindowFocus v-slot="{ focused }">
  Document Focus: {{ focused }}
</UseWindowFocus>

Type Declarations

/**
 * Reactively track window focus with `window.onfocus` and `window.onblur`.
 *
 * @see https://vueuse.org/useWindowFocus
 * @param options
 */
export declare function useWindowFocus({
  window,
}?: ConfigurableWindow): Ref<boolean>
/**
 * Reactively track window focus with `window.onfocus` and `window.onblur`.
 *
 * @see https://vueuse.org/useWindowFocus
 * @param options
 */
export declare function useWindowFocus({
  window,
}?: ConfigurableWindow): Ref<boolean>

Source

Source • Demo • Docs

Contributors

Anthony Fu
vaaski

Changelog

v5.1.0 on 7/5/2021
97328 - feat: new function (#601)
useWindowFocus has loaded