Files
30-seconds-of-code/snippets/isBrowserTabFocused.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

377 B

title, tags
title tags
isBrowserTabFocused 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.

const isBrowserTabFocused = () => !document.hidden;
isBrowserTabFocused(); // true