Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..
При переключении между вкладками, web страница переходит в фоновый режим и поэтому не видна пользователю. Page Visibility API предоставляет события, которые вы можете отслеживать, чтобы узнать, когда страница станет видимой или скрытой, а так же возможность наблюдать текущее состояние видимости страницы.
Когда пользователь сворачивает окно или переключается на другую вкладку, API отправляет событие visibilitychange обработчикам. Вы можете отследить это событие и выполнить какие-то действия. Например, если ваше приложение проигрывает видео, его можно поставить на паузу, когда пользователь переключил вкладку (страница ушла в фон), а затем возобновить видео, когда пользователь вернулся на вкладку. Пользователь не теряет место на котором остановил просмотр, звук от видео не конфликтует с аудио новой вкладки, пользователь может комфортно просмотреть оба видео.
Состояния видимости для <iframe> такие же как и для родительской страницы. Скрытие <iframe> используя CSS стили (такие как display: none;) не вызывают события видимости и не изменяют состояние документа, содержащегося во фрейме.
Давайте рассмотрим несколько способов использования Page Visibility API.
Раньше у разработчиков были неудобные способы. Например, обработка событий blur и focus на объекте window помогала узнать когда страница становилась не активной, но это не давало возможность понять когда страница действительно скрыта от пользователя. Page Visibility API решает эту проблему.
Примечание: Когда onblur и onfocus уведомляют, что пользователь переключил окна, это не означает, что оно действительно скрыто. Страница действительно скрыта, когда пользователь переключил вкладки или свернул окно браузера с этой вкладкой.
Separately from the Page Visibility API, user agents typically have a number of policies in place to mitigate the performance impact of background or hidden tabs. These may include:
Some processes are exempt from this throttling behavior. In these cases, you can use the Page Visibility API to reduce the tabs' performance impact while they're hidden.
View live example (video with sound).
The example, which pauses the video when you switch to another tab and plays again when you return to its tab, was created with the following code:
The Page Visibility API adds the following properties to the Document interface:
Document.hidden Только для чтенияReturns true if the page is in a state considered to be hidden to the user, and false otherwise.
Document.visibilityState Только для чтенияA DOMString indicating the document's current visibility state. Possible values are:
visibleThe page content may be at least partially visible. In practice this means that the page is the foreground tab of a non-minimized window.
hiddenThe page's content is not visible to the user, either due to the document's tab being in the background or part of a window that is minimized, or because the device's screen is off.
prerenderThe page's content is being prerendered and is not visible to the user. A document may start in the prerender state, but will never switch to this state from any other state, since a document can only prerender once.
unloadedThe page is in the process of being unloaded from memory.
Document.onvisibilitychangeAn EventListener providing the code to be called when the visibilitychange event is fired.
| HTML # dom-document-visibilitystate |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 24 июн. 2025 г. by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.