isBrowserTabFocused

JavaScript, Browser

Checks if the browser tab of the page is focused.

  • 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

Recommended snippets

  • bottomVisible

    JavaScript, Browser

    Checks if the bottom of the page is visible.

  • elementIsFocused

    JavaScript, Browser

    Checks if the given element is focused.

  • httpsRedirect

    JavaScript, Browser

    Redirects the page to HTTPS if it's currently in HTTP.