Files
30-seconds-of-code/snippets/isBrowserTabFocused.md
2020-09-15 21:52:00 +03:00

17 lines
380 B
Markdown

---
title: isBrowserTabFocused
tags: browser,beginner
---
Returns `true` if the browser tab of the page is focused, `false` otherwise.
- Use the `Document.hidden` property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden.
```js
const isBrowserTabFocused = () => !document.hidden;
```
```js
isBrowserTabFocused(); // true
```